import{S as to,i as ao,s as lo,e as _,t as n,k as m,w as q,c,a as u,h as r,d as e,m as f,x as E,g as o,G as t,y as x,q as b,o as g,B as z,b as H,l as qn,M as no,N as vn,p as na,v as ro,n as ra}from"../../chunks/vendor-hf-doc-builder.js";import{T as oa}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Vn}from"../../chunks/Youtube-hf-doc-builder.js";import{I as oo}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as T}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as eo}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as po}from"../../chunks/FrameworkSwitchCourse-hf-doc-builder.js";function io(O){let l,d;return l=new eo({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/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section6_tf.ipynb"}]}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function _o(O){let l,d;return l=new eo({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/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section6_pt.ipynb"}]}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function co(O){let l,d;return{c(){l=_("p"),d=n("\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u9700\u8981\u4E00\u6BB5\u65F6\u95F4\u3002\u6211\u4EEC\u5EFA\u8BAE\u60A8\u9996\u5148\u901A\u8FC7\u53D6\u6D88\u6CE8\u91CA\u4EE5\u4E0A\u4E24\u884C\u7684\u6CE8\u91CA\u5BF9\u6570\u636E\u6837\u672C\u8FD0\u884C\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u5E76\u786E\u4FDD\u8BAD\u7EC3\u6210\u529F\u5B8C\u6210\u5E76\u5B58\u50A8\u6A21\u578B\u3002\u6CA1\u6709\u4EC0\u4E48\u6BD4\u6700\u540E\u4E00\u6B65\u7684\u8BAD\u7EC3\u5931\u8D25\u66F4\u4EE4\u4EBA\u6CAE\u4E27\u7684\u4E86\uFF0C\u56E0\u4E3A\u4F60\u5FD8\u8BB0\u521B\u5EFA\u4E00\u4E2A\u6587\u4EF6\u5939\u6216\u8005\u56E0\u4E3A\u4FDD\u5B58\u8DEF\u5F84\u5728\u8BAD\u7EC3\u5FAA\u73AF\u7ED3\u675F\u65F6\u6709\u4E00\u4E2A\u9519\u5B57\uFF01")},l(p){l=c(p,"P",{});var h=u(l);d=r(h,"\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u9700\u8981\u4E00\u6BB5\u65F6\u95F4\u3002\u6211\u4EEC\u5EFA\u8BAE\u60A8\u9996\u5148\u901A\u8FC7\u53D6\u6D88\u6CE8\u91CA\u4EE5\u4E0A\u4E24\u884C\u7684\u6CE8\u91CA\u5BF9\u6570\u636E\u6837\u672C\u8FD0\u884C\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u5E76\u786E\u4FDD\u8BAD\u7EC3\u6210\u529F\u5B8C\u6210\u5E76\u5B58\u50A8\u6A21\u578B\u3002\u6CA1\u6709\u4EC0\u4E48\u6BD4\u6700\u540E\u4E00\u6B65\u7684\u8BAD\u7EC3\u5931\u8D25\u66F4\u4EE4\u4EBA\u6CAE\u4E27\u7684\u4E86\uFF0C\u56E0\u4E3A\u4F60\u5FD8\u8BB0\u521B\u5EFA\u4E00\u4E2A\u6587\u4EF6\u5939\u6216\u8005\u56E0\u4E3A\u4FDD\u5B58\u8DEF\u5F84\u5728\u8BAD\u7EC3\u5FAA\u73AF\u7ED3\u675F\u65F6\u6709\u4E00\u4E2A\u9519\u5B57\uFF01"),h.forEach(e)},m(p,h){o(p,l,h),t(l,d)},d(p){p&&e(l)}}}function uo(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M;return{c(){l=_("p"),d=n("\u270F\uFE0F "),p=_("strong"),h=n("\u8BD5\u8BD5\u770B\uFF01"),y=n(" \u6446\u8131\u6240\u6709\u5C0F\u4E8E\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u5757\u5728\u8FD9\u91CC\u5E76\u4E0D\u662F\u4EC0\u4E48\u5927\u95EE\u9898\uFF0C\u56E0\u4E3A\u6211\u4EEC\u4F7F\u7528\u7684\u662F\u5C0F\u4E0A\u4E0B\u6587\u7A97\u53E3\u3002\u968F\u7740\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u589E\u52A0\uFF08\u6216\u8005\u5982\u679C\u60A8\u6709\u4E00\u4E2A\u77ED\u6587\u6863\u8BED\u6599\u5E93\uFF09\uFF0C\u88AB\u4E22\u5F03\u7684\u5757\u7684\u6BD4\u4F8B\u4E5F\u4F1A\u589E\u52A0\u3002\u51C6\u5907\u6570\u636E\u7684\u66F4\u6709\u6548\u65B9\u6CD5\u662F\u5C06\u6240\u6709\u6807\u8BB0\u5316\u7684\u6837\u672C\u52A0\u5165\u4E00\u4E2A\u6279\u6B21\u4E2D\uFF0C\u6BCF\u4E2A\u8BED\u6599\u4E4B\u95F4\u6709\u4E00\u4E2A"),j=_("code"),v=n("eos_token_id"),P=n(" \u6807\u8BB0, \u7136\u540E\u5BF9\u8FDE\u63A5\u7684\u5E8F\u5217\u6267\u884C\u5206\u5757\u3002\u4F5C\u4E3A\u7EC3\u4E60\uFF0C\u4FEE\u6539 "),w=_("code"),D=n("tokenize()"),G=n("\u51FD\u6570\u4EE5\u4F7F\u7528\u8BE5\u65B9\u6CD5\u3002\u8BF7\u6CE8\u610F\uFF0C\u60A8\u9700\u8981\u8BBE\u7F6E"),L=_("code"),$=n("truncation=False"),M=n(" \u548C\u5220\u9664\u6807\u8BB0\u751F\u6210\u5668\u4E2D\u7684\u5176\u4ED6\u53C2\u6570\u4EE5\u83B7\u53D6\u5B8C\u6574\u7684\u6807\u8BB0 ID \u5E8F\u5217\u3002")},l(I){l=c(I,"P",{});var R=u(l);d=r(R,"\u270F\uFE0F "),p=c(R,"STRONG",{});var A=u(p);h=r(A,"\u8BD5\u8BD5\u770B\uFF01"),A.forEach(e),y=r(R," \u6446\u8131\u6240\u6709\u5C0F\u4E8E\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u5757\u5728\u8FD9\u91CC\u5E76\u4E0D\u662F\u4EC0\u4E48\u5927\u95EE\u9898\uFF0C\u56E0\u4E3A\u6211\u4EEC\u4F7F\u7528\u7684\u662F\u5C0F\u4E0A\u4E0B\u6587\u7A97\u53E3\u3002\u968F\u7740\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u589E\u52A0\uFF08\u6216\u8005\u5982\u679C\u60A8\u6709\u4E00\u4E2A\u77ED\u6587\u6863\u8BED\u6599\u5E93\uFF09\uFF0C\u88AB\u4E22\u5F03\u7684\u5757\u7684\u6BD4\u4F8B\u4E5F\u4F1A\u589E\u52A0\u3002\u51C6\u5907\u6570\u636E\u7684\u66F4\u6709\u6548\u65B9\u6CD5\u662F\u5C06\u6240\u6709\u6807\u8BB0\u5316\u7684\u6837\u672C\u52A0\u5165\u4E00\u4E2A\u6279\u6B21\u4E2D\uFF0C\u6BCF\u4E2A\u8BED\u6599\u4E4B\u95F4\u6709\u4E00\u4E2A"),j=c(R,"CODE",{});var B=u(j);v=r(B,"eos_token_id"),B.forEach(e),P=r(R," \u6807\u8BB0, \u7136\u540E\u5BF9\u8FDE\u63A5\u7684\u5E8F\u5217\u6267\u884C\u5206\u5757\u3002\u4F5C\u4E3A\u7EC3\u4E60\uFF0C\u4FEE\u6539 "),w=c(R,"CODE",{});var W=u(w);D=r(W,"tokenize()"),W.forEach(e),G=r(R,"\u51FD\u6570\u4EE5\u4F7F\u7528\u8BE5\u65B9\u6CD5\u3002\u8BF7\u6CE8\u610F\uFF0C\u60A8\u9700\u8981\u8BBE\u7F6E"),L=c(R,"CODE",{});var F=u(L);$=r(F,"truncation=False"),F.forEach(e),M=r(R," \u548C\u5220\u9664\u6807\u8BB0\u751F\u6210\u5668\u4E2D\u7684\u5176\u4ED6\u53C2\u6570\u4EE5\u83B7\u53D6\u5B8C\u6574\u7684\u6807\u8BB0 ID \u5E8F\u5217\u3002"),R.forEach(e)},m(I,R){o(I,l,R),t(l,d),t(l,p),t(p,h),t(l,y),t(l,j),t(j,v),t(l,P),t(l,w),t(w,D),t(l,G),t(l,L),t(L,$),t(l,M)},d(I){I&&e(l)}}}function mo(O){let l,d,p,h,y,j,v,P,w,D,G,L;return l=new T({props:{code:`from transformers import AutoTokenizer, TFGPT2LMHeadModel, AutoConfig

config = AutoConfig.from_pretrained(
    "gpt2",
    vocab_size=len(tokenizer),
    n_ctx=context_length,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFGPT2LMHeadModel, AutoConfig

config = AutoConfig.from_pretrained(
    <span class="hljs-string">&quot;gpt2&quot;</span>,
    vocab_size=<span class="hljs-built_in">len</span>(tokenizer),
    n_ctx=context_length,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
)`}}),w=new T({props:{code:`model = TFGPT2LMHeadModel(config)
model(model.dummy_inputs)  # Builds the model
model.summary()`,highlighted:`model = TFGPT2LMHeadModel(config)
model(model.dummy_inputs)  <span class="hljs-comment"># Builds the model</span>
model.summary()`}}),G=new T({props:{code:`_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
transformer (TFGPT2MainLayer multiple                  124242432 
=================================================================
Total params: 124,242,432
Trainable params: 124,242,432
Non-trainable params: 0
_________________________________________________________________`,highlighted:`_________________________________________________________________
Layer (<span class="hljs-built_in">type</span>)                 Output Shape              Param <span class="hljs-comment">#   </span>
=================================================================
transformer (TFGPT2MainLayer multiple                  <span class="hljs-number">124242432</span> 
=================================================================
Total params: <span class="hljs-number">124</span>,<span class="hljs-number">242</span>,<span class="hljs-number">432</span>
Trainable params: <span class="hljs-number">124</span>,<span class="hljs-number">242</span>,<span class="hljs-number">432</span>
Non-trainable params: <span class="hljs-number">0</span>
_________________________________________________________________`}}),{c(){q(l.$$.fragment),d=m(),p=_("p"),h=n("\u901A\u8FC7\u8BE5\u914D\u7F6E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u52A0\u8F7D\u65B0\u6A21\u578B\u3002\u8BF7\u6CE8\u610F\uFF0C\u8FD9\u662F\u6211\u4EEC\u521A\u5F00\u59CB\u4E0D\u4F7F\u7528"),y=_("code"),j=n("from_pretrained()"),v=n("\u51FD\u6570\uFF0C\u56E0\u4E3A\u6211\u4EEC\u5B9E\u9645\u4E0A\u662F\u5728\u81EA\u5DF1\u521D\u59CB\u5316\u6A21\u578B\uFF1A"),P=m(),q(w.$$.fragment),D=m(),q(G.$$.fragment)},l($){E(l.$$.fragment,$),d=f($),p=c($,"P",{});var M=u(p);h=r(M,"\u901A\u8FC7\u8BE5\u914D\u7F6E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u52A0\u8F7D\u65B0\u6A21\u578B\u3002\u8BF7\u6CE8\u610F\uFF0C\u8FD9\u662F\u6211\u4EEC\u521A\u5F00\u59CB\u4E0D\u4F7F\u7528"),y=c(M,"CODE",{});var I=u(y);j=r(I,"from_pretrained()"),I.forEach(e),v=r(M,"\u51FD\u6570\uFF0C\u56E0\u4E3A\u6211\u4EEC\u5B9E\u9645\u4E0A\u662F\u5728\u81EA\u5DF1\u521D\u59CB\u5316\u6A21\u578B\uFF1A"),M.forEach(e),P=f($),E(w.$$.fragment,$),D=f($),E(G.$$.fragment,$)},m($,M){x(l,$,M),o($,d,M),o($,p,M),t(p,h),t(p,y),t(y,j),t(p,v),o($,P,M),x(w,$,M),o($,D,M),x(G,$,M),L=!0},i($){L||(b(l.$$.fragment,$),b(w.$$.fragment,$),b(G.$$.fragment,$),L=!0)},o($){g(l.$$.fragment,$),g(w.$$.fragment,$),g(G.$$.fragment,$),L=!1},d($){z(l,$),$&&e(d),$&&e(p),$&&e(P),z(w,$),$&&e(D),z(G,$)}}}function fo(O){let l,d,p,h,y,j,v,P,w,D,G,L;return l=new T({props:{code:`from transformers import AutoTokenizer, GPT2LMHeadModel, AutoConfig

config = AutoConfig.from_pretrained(
    "gpt2",
    vocab_size=len(tokenizer),
    n_ctx=context_length,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, GPT2LMHeadModel, AutoConfig

config = AutoConfig.from_pretrained(
    <span class="hljs-string">&quot;gpt2&quot;</span>,
    vocab_size=<span class="hljs-built_in">len</span>(tokenizer),
    n_ctx=context_length,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
)`}}),w=new T({props:{code:`model = GPT2LMHeadModel(config)
model_size = sum(t.numel() for t in model.parameters())
print(f"GPT-2 size: {model_size/1000**2:.1f}M parameters")`,highlighted:`model = GPT2LMHeadModel(config)
model_size = <span class="hljs-built_in">sum</span>(t.numel() <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> model.parameters())
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;GPT-2 size: <span class="hljs-subst">{model_size/<span class="hljs-number">1000</span>**<span class="hljs-number">2</span>:<span class="hljs-number">.1</span>f}</span>M parameters&quot;</span>)`}}),G=new T({props:{code:"GPT-2 size: 124.2M parameters",highlighted:'GPT-<span class="hljs-number">2</span> size: <span class="hljs-number">124.2</span>M parameters'}}),{c(){q(l.$$.fragment),d=m(),p=_("p"),h=n("\u4F7F\u7528\u8BE5\u914D\u7F6E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u52A0\u8F7D\u4E00\u4E2A\u65B0\u6A21\u578B\u3002\u8BF7\u6CE8\u610F\uFF0C\u8FD9\u662F\u6211\u4EEC\u7B2C\u4E00\u6B21\u4E0D\u4F7F\u7528 "),y=_("code"),j=n("from_pretrained()"),v=n(" \u51FD\u6570\uFF0C\u56E0\u4E3A\u6211\u4EEC\u5B9E\u9645\u4E0A\u662F\u5728\u81EA\u5DF1\u521D\u59CB\u5316\u6A21\u578B"),P=m(),q(w.$$.fragment),D=m(),q(G.$$.fragment)},l($){E(l.$$.fragment,$),d=f($),p=c($,"P",{});var M=u(p);h=r(M,"\u4F7F\u7528\u8BE5\u914D\u7F6E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u52A0\u8F7D\u4E00\u4E2A\u65B0\u6A21\u578B\u3002\u8BF7\u6CE8\u610F\uFF0C\u8FD9\u662F\u6211\u4EEC\u7B2C\u4E00\u6B21\u4E0D\u4F7F\u7528 "),y=c(M,"CODE",{});var I=u(y);j=r(I,"from_pretrained()"),I.forEach(e),v=r(M," \u51FD\u6570\uFF0C\u56E0\u4E3A\u6211\u4EEC\u5B9E\u9645\u4E0A\u662F\u5728\u81EA\u5DF1\u521D\u59CB\u5316\u6A21\u578B"),M.forEach(e),P=f($),E(w.$$.fragment,$),D=f($),E(G.$$.fragment,$)},m($,M){x(l,$,M),o($,d,M),o($,p,M),t(p,h),t(p,y),t(y,j),t(p,v),o($,P,M),x(w,$,M),o($,D,M),x(G,$,M),L=!0},i($){L||(b(l.$$.fragment,$),b(w.$$.fragment,$),b(G.$$.fragment,$),L=!0)},o($){g(l.$$.fragment,$),g(w.$$.fragment,$),g(G.$$.fragment,$),L=!1},d($){z(l,$),$&&e(d),$&&e(p),$&&e(P),z(w,$),$&&e(D),z(G,$)}}}function ho(O){let l,d;return l=new T({props:{code:`from transformers import DataCollatorForLanguageModeling

tokenizer.pad_token = tokenizer.eos_token
data_collator = DataCollatorForLanguageModeling(tokenizer, mlm=False, return_tensors="tf")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForLanguageModeling

tokenizer.pad_token = tokenizer.eos_token
data_collator = DataCollatorForLanguageModeling(tokenizer, mlm=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function $o(O){let l,d;return l=new T({props:{code:`from transformers import DataCollatorForLanguageModeling

tokenizer.pad_token = tokenizer.eos_token
data_collator = DataCollatorForLanguageModeling(tokenizer, mlm=False)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForLanguageModeling

tokenizer.pad_token = tokenizer.eos_token
data_collator = DataCollatorForLanguageModeling(tokenizer, mlm=<span class="hljs-literal">False</span>)`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function bo(O){let l,d;return l=new T({props:{code:`input_ids shape: (5, 128)
attention_mask shape: (5, 128)
labels shape: (5, 128)`,highlighted:`input_ids shape: (<span class="hljs-number">5</span>, <span class="hljs-number">128</span>)
attention_mask shape: (<span class="hljs-number">5</span>, <span class="hljs-number">128</span>)
labels shape: (<span class="hljs-number">5</span>, <span class="hljs-number">128</span>)`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function go(O){let l,d;return l=new T({props:{code:`input_ids shape: torch.Size([5, 128])
attention_mask shape: torch.Size([5, 128])
labels shape: torch.Size([5, 128])`,highlighted:`input_ids shape: torch.Size([<span class="hljs-number">5</span>, <span class="hljs-number">128</span>])
attention_mask shape: torch.Size([<span class="hljs-number">5</span>, <span class="hljs-number">128</span>])
labels shape: torch.Size([<span class="hljs-number">5</span>, <span class="hljs-number">128</span>])`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function Qr(O){let l,d,p,h,y,j,v,P;return v=new T({props:{code:`tf_train_dataset = tokenized_dataset["train"].to_tf_dataset(
    columns=["input_ids", "attention_mask", "labels"],
    collate_fn=data_collator,
    shuffle=True,
    batch_size=32,
)
tf_eval_dataset = tokenized_dataset["valid"].to_tf_dataset(
    columns=["input_ids", "attention_mask", "labels"],
    collate_fn=data_collator,
    shuffle=False,
    batch_size=32,
)`,highlighted:`tf_train_dataset = tokenized_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 = tokenized_dataset[<span class="hljs-string">&quot;valid&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>,
)`}}),{c(){l=_("p"),d=n("\u73B0\u5728\uFF0C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528"),p=_("code"),h=n("to_tf_dataset()"),y=n("\u65B9\u6CD5\uFF0C\u4F7F\u7528\u4E0A\u9762\u521B\u5EFA\u7684\u6570\u636E\u6574\u7406\u5668\u5C06\u6570\u636E\u96C6\u8F6C\u6362\u4E3ATensorFlow\u6570\u636E\u96C6\uFF1A"),j=m(),q(v.$$.fragment)},l(w){l=c(w,"P",{});var D=u(l);d=r(D,"\u73B0\u5728\uFF0C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528"),p=c(D,"CODE",{});var G=u(p);h=r(G,"to_tf_dataset()"),G.forEach(e),y=r(D,"\u65B9\u6CD5\uFF0C\u4F7F\u7528\u4E0A\u9762\u521B\u5EFA\u7684\u6570\u636E\u6574\u7406\u5668\u5C06\u6570\u636E\u96C6\u8F6C\u6362\u4E3ATensorFlow\u6570\u636E\u96C6\uFF1A"),D.forEach(e),j=f(w),E(v.$$.fragment,w)},m(w,D){o(w,l,D),t(l,d),t(l,p),t(p,h),t(l,y),o(w,j,D),x(v,w,D),P=!0},i(w){P||(b(v.$$.fragment,w),P=!0)},o(w){g(v.$$.fragment,w),P=!1},d(w){w&&e(l),w&&e(j),z(v,w)}}}function ko(O){let l,d;return{c(){l=_("p"),d=n("\u26A0\uFE0F  \u79FB\u52A8\u8F93\u5165\u548C\u6807\u7B7E\u4EE5\u5BF9\u9F50\u5B83\u4EEC\u53D1\u751F\u5728\u6A21\u578B\u5185\u90E8\uFF0C\u56E0\u6B64\u6570\u636E\u6574\u7406\u5668\u53EA\u9700\u590D\u5236\u8F93\u5165\u4EE5\u521B\u5EFA\u6807\u7B7E\u3002")},l(p){l=c(p,"P",{});var h=u(l);d=r(h,"\u26A0\uFE0F  \u79FB\u52A8\u8F93\u5165\u548C\u6807\u7B7E\u4EE5\u5BF9\u9F50\u5B83\u4EEC\u53D1\u751F\u5728\u6A21\u578B\u5185\u90E8\uFF0C\u56E0\u6B64\u6570\u636E\u6574\u7406\u5668\u53EA\u9700\u590D\u5236\u8F93\u5165\u4EE5\u521B\u5EFA\u6807\u7B7E\u3002"),h.forEach(e)},m(p,h){o(p,l,h),t(l,d)},d(p){p&&e(l)}}}function jo(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M,I,R,A,B,W;return D=new T({props:{code:`from transformers import create_optimizer
import tensorflow as tf

num_train_steps = len(tf_train_dataset)
optimizer, schedule = create_optimizer(
    init_lr=5e-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")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset)
optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">5e-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>)`}}),B=new T({props:{code:`from transformers.keras_callbacks import PushToHubCallback

callback = PushToHubCallback(output_dir="codeparrot-ds", tokenizer=tokenizer)

model.fit(tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback])`,highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

callback = PushToHubCallback(output_dir=<span class="hljs-string">&quot;codeparrot-ds&quot;</span>, tokenizer=tokenizer)

model.fit(tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback])`}}),{c(){l=_("p"),d=n("\u5269\u4E0B\u8981\u505A\u7684\u5C31\u662F\u914D\u7F6E\u8BAD\u7EC3\u8D85\u53C2\u6570\u5E76\u8C03\u7528 "),p=_("code"),h=n("compile()"),y=n(" \u548C "),j=_("code"),v=n("fit()"),P=n("\u3002\u6211\u4EEC\u5C06\u4F7F\u7528\u5E26\u6709\u4E00\u4E9B\u9884\u70ED\u7684\u5B66\u4E60\u7387\u8C03\u6574\u7B56\u7565\u6765\u63D0\u9AD8\u8BAD\u7EC3\u7684\u7A33\u5B9A\u6027\uFF1A"),w=m(),q(D.$$.fragment),G=m(),L=_("p"),$=n("\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u8C03\u7528"),M=_("code"),I=n("model.fit()\uFF0C"),R=n("\u5E76\u7B49\u5F85\u8BAD\u7EC3\u5B8C\u6210\u3002\u4F60\u662F\u5728\u5B8C\u6574\u7684\u8BAD\u7EC3\u96C6\u8FD8\u662F\u4ED6\u7684\u5B50\u96C6\u4E0A\u8FD0\u884C\uFF0C\u8FD9\u5C06\u5206\u522B\u9700\u898120\u548C2\u4E2A\u5C0F\u65F6\uFF0C\u6240\u4EE5\u62FF\u4E00\u4E9B\u5496\u5561\u548C\u4E00\u672C\u597D\u4E66\u6765\u9605\u8BFB\uFF01\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5C06\u6A21\u578B\u548C\u5206\u8BCD\u5668\u63A8\u9001\u5230\u4E2D\u5FC3\uFF1A"),A=m(),q(B.$$.fragment)},l(F){l=c(F,"P",{});var N=u(l);d=r(N,"\u5269\u4E0B\u8981\u505A\u7684\u5C31\u662F\u914D\u7F6E\u8BAD\u7EC3\u8D85\u53C2\u6570\u5E76\u8C03\u7528 "),p=c(N,"CODE",{});var S=u(p);h=r(S,"compile()"),S.forEach(e),y=r(N," \u548C "),j=c(N,"CODE",{});var Y=u(j);v=r(Y,"fit()"),Y.forEach(e),P=r(N,"\u3002\u6211\u4EEC\u5C06\u4F7F\u7528\u5E26\u6709\u4E00\u4E9B\u9884\u70ED\u7684\u5B66\u4E60\u7387\u8C03\u6574\u7B56\u7565\u6765\u63D0\u9AD8\u8BAD\u7EC3\u7684\u7A33\u5B9A\u6027\uFF1A"),N.forEach(e),w=f(F),E(D.$$.fragment,F),G=f(F),L=c(F,"P",{});var Z=u(L);$=r(Z,"\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u8C03\u7528"),M=c(Z,"CODE",{});var K=u(M);I=r(K,"model.fit()\uFF0C"),K.forEach(e),R=r(Z,"\u5E76\u7B49\u5F85\u8BAD\u7EC3\u5B8C\u6210\u3002\u4F60\u662F\u5728\u5B8C\u6574\u7684\u8BAD\u7EC3\u96C6\u8FD8\u662F\u4ED6\u7684\u5B50\u96C6\u4E0A\u8FD0\u884C\uFF0C\u8FD9\u5C06\u5206\u522B\u9700\u898120\u548C2\u4E2A\u5C0F\u65F6\uFF0C\u6240\u4EE5\u62FF\u4E00\u4E9B\u5496\u5561\u548C\u4E00\u672C\u597D\u4E66\u6765\u9605\u8BFB\uFF01\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5C06\u6A21\u578B\u548C\u5206\u8BCD\u5668\u63A8\u9001\u5230\u4E2D\u5FC3\uFF1A"),Z.forEach(e),A=f(F),E(B.$$.fragment,F)},m(F,N){o(F,l,N),t(l,d),t(l,p),t(p,h),t(l,y),t(l,j),t(j,v),t(l,P),o(F,w,N),x(D,F,N),o(F,G,N),o(F,L,N),t(L,$),t(L,M),t(M,I),t(L,R),o(F,A,N),x(B,F,N),W=!0},i(F){W||(b(D.$$.fragment,F),b(B.$$.fragment,F),W=!0)},o(F){g(D.$$.fragment,F),g(B.$$.fragment,F),W=!1},d(F){F&&e(l),F&&e(w),z(D,F),F&&e(G),F&&e(L),F&&e(A),z(B,F)}}}function wo(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M,I,R,A,B,W,F,N,S,Y,Z,K,es,is;return $=new T({props:{code:`from transformers import Trainer, TrainingArguments

args = TrainingArguments(
    output_dir="codeparrot-ds",
    per_device_train_batch_size=32,
    per_device_eval_batch_size=32,
    evaluation_strategy="steps",
    eval_steps=5_000,
    logging_steps=5_000,
    gradient_accumulation_steps=8,
    num_train_epochs=1,
    weight_decay=0.1,
    warmup_steps=1_000,
    lr_scheduler_type="cosine",
    learning_rate=5e-4,
    save_steps=5_000,
    fp16=True,
    push_to_hub=True,
)

trainer = Trainer(
    model=model,
    tokenizer=tokenizer,
    args=args,
    data_collator=data_collator,
    train_dataset=tokenized_datasets["train"],
    eval_dataset=tokenized_datasets["valid"],
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer, TrainingArguments

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;codeparrot-ds&quot;</span>,
    per_device_train_batch_size=<span class="hljs-number">32</span>,
    per_device_eval_batch_size=<span class="hljs-number">32</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    eval_steps=<span class="hljs-number">5_000</span>,
    logging_steps=<span class="hljs-number">5_000</span>,
    gradient_accumulation_steps=<span class="hljs-number">8</span>,
    num_train_epochs=<span class="hljs-number">1</span>,
    weight_decay=<span class="hljs-number">0.1</span>,
    warmup_steps=<span class="hljs-number">1_000</span>,
    lr_scheduler_type=<span class="hljs-string">&quot;cosine&quot;</span>,
    learning_rate=<span class="hljs-number">5e-4</span>,
    save_steps=<span class="hljs-number">5_000</span>,
    fp16=<span class="hljs-literal">True</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)

trainer = Trainer(
    model=model,
    tokenizer=tokenizer,
    args=args,
    data_collator=data_collator,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;valid&quot;</span>],
)`}}),N=new T({props:{code:"trainer.train()",highlighted:"trainer.train()"}}),es=new T({props:{code:"trainer.push_to_hub()",highlighted:"trainer.push_to_hub()"}}),{c(){l=_("p"),d=n("\u5269\u4E0B\u8981\u505A\u7684\u5C31\u662F\u914D\u7F6E\u8BAD\u7EC3\u53C2\u6570\u5E76\u542F\u52A8 "),p=_("code"),h=n("Trainer"),y=n(" .\u6211\u4EEC\u5C06\u4F7F\u7528\u4F59\u5F26\u5B66\u4E60\u7387\uFF0C\u5E76\u8FDB\u884C\u4E00\u4E9BWarmup\u548C\u6709\u6548\u6279\u91CF\u5927\u5C0F\u4E3A 256 ( "),j=_("code"),v=n("per_device_train_batch_size"),P=n(" * "),w=_("code"),D=n("gradient_accumulation_steps"),G=n("\uFF09\u3002\u5F53\u5355\u4E2A\u6279\u6B21\u4E0D\u9002\u5408\u5185\u5B58\u65F6\u4F7F\u7528\u68AF\u5EA6\u7D2F\u79EF\uFF0C\u5E76\u901A\u8FC7\u591A\u6B21\u5411\u524D/\u5411\u540E\u4F20\u9012\u9010\u6B65\u5EFA\u7ACB\u68AF\u5EA6\u3002\u5F53\u6211\u4EEC\u4F7F\u7528 \u{1F917} Accelerate \u521B\u5EFA\u8BAD\u7EC3\u5FAA\u73AF\u65F6\uFF0C\u6211\u4EEC\u5C06\u770B\u5230\u8FD9\u4E00\u70B9\u3002"),L=m(),q($.$$.fragment),M=m(),I=_("p"),R=n("\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5F00\u59CB "),A=_("code"),B=n("Trainer"),W=n("\u5E76\u7B49\u5F85\u8BAD\u7EC3\u5B8C\u6210\u3002\u6839\u636E\u60A8\u662F\u5728\u6574\u4E2A\u8BAD\u7EC3\u96C6\u8FD8\u662F\u5728\u8BAD\u7EC3\u96C6\u7684\u4E00\u4E2A\u5B50\u96C6\u4E0A\u8FD0\u884C\u5B83\uFF0C\u8FD9\u5C06\u5206\u522B\u9700\u8981 20 \u6216 2 \u4E2A\u5C0F\u65F6\uFF0C\u56E0\u6B64\u8BF7\u559D\u676F\u5496\u5561\u548C\u4E00\u672C\u597D\u4E66\u6765\u9605\u8BFB\uFF01"),F=m(),q(N.$$.fragment),S=m(),Y=_("p"),Z=n("\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5C06\u6A21\u578B\u548C\u6807\u8BB0\u5668\u63A8\u9001\u5230 Hub\uFF1A"),K=m(),q(es.$$.fragment)},l(C){l=c(C,"P",{});var U=u(l);d=r(U,"\u5269\u4E0B\u8981\u505A\u7684\u5C31\u662F\u914D\u7F6E\u8BAD\u7EC3\u53C2\u6570\u5E76\u542F\u52A8 "),p=c(U,"CODE",{});var Pe=u(p);h=r(Pe,"Trainer"),Pe.forEach(e),y=r(U," .\u6211\u4EEC\u5C06\u4F7F\u7528\u4F59\u5F26\u5B66\u4E60\u7387\uFF0C\u5E76\u8FDB\u884C\u4E00\u4E9BWarmup\u548C\u6709\u6548\u6279\u91CF\u5927\u5C0F\u4E3A 256 ( "),j=c(U,"CODE",{});var qs=u(j);v=r(qs,"per_device_train_batch_size"),qs.forEach(e),P=r(U," * "),w=c(U,"CODE",{});var hs=u(w);D=r(hs,"gradient_accumulation_steps"),hs.forEach(e),G=r(U,"\uFF09\u3002\u5F53\u5355\u4E2A\u6279\u6B21\u4E0D\u9002\u5408\u5185\u5B58\u65F6\u4F7F\u7528\u68AF\u5EA6\u7D2F\u79EF\uFF0C\u5E76\u901A\u8FC7\u591A\u6B21\u5411\u524D/\u5411\u540E\u4F20\u9012\u9010\u6B65\u5EFA\u7ACB\u68AF\u5EA6\u3002\u5F53\u6211\u4EEC\u4F7F\u7528 \u{1F917} Accelerate \u521B\u5EFA\u8BAD\u7EC3\u5FAA\u73AF\u65F6\uFF0C\u6211\u4EEC\u5C06\u770B\u5230\u8FD9\u4E00\u70B9\u3002"),U.forEach(e),L=f(C),E($.$$.fragment,C),M=f(C),I=c(C,"P",{});var Es=u(I);R=r(Es,"\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5F00\u59CB "),A=c(Es,"CODE",{});var J=u(A);B=r(J,"Trainer"),J.forEach(e),W=r(Es,"\u5E76\u7B49\u5F85\u8BAD\u7EC3\u5B8C\u6210\u3002\u6839\u636E\u60A8\u662F\u5728\u6574\u4E2A\u8BAD\u7EC3\u96C6\u8FD8\u662F\u5728\u8BAD\u7EC3\u96C6\u7684\u4E00\u4E2A\u5B50\u96C6\u4E0A\u8FD0\u884C\u5B83\uFF0C\u8FD9\u5C06\u5206\u522B\u9700\u8981 20 \u6216 2 \u4E2A\u5C0F\u65F6\uFF0C\u56E0\u6B64\u8BF7\u559D\u676F\u5496\u5561\u548C\u4E00\u672C\u597D\u4E66\u6765\u9605\u8BFB\uFF01"),Es.forEach(e),F=f(C),E(N.$$.fragment,C),S=f(C),Y=c(C,"P",{});var Te=u(Y);Z=r(Te,"\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5C06\u6A21\u578B\u548C\u6807\u8BB0\u5668\u63A8\u9001\u5230 Hub\uFF1A"),Te.forEach(e),K=f(C),E(es.$$.fragment,C)},m(C,U){o(C,l,U),t(l,d),t(l,p),t(p,h),t(l,y),t(l,j),t(j,v),t(l,P),t(l,w),t(w,D),t(l,G),o(C,L,U),x($,C,U),o(C,M,U),o(C,I,U),t(I,R),t(I,A),t(A,B),t(I,W),o(C,F,U),x(N,C,U),o(C,S,U),o(C,Y,U),t(Y,Z),o(C,K,U),x(es,C,U),is=!0},i(C){is||(b($.$$.fragment,C),b(N.$$.fragment,C),b(es.$$.fragment,C),is=!0)},o(C){g($.$$.fragment,C),g(N.$$.fragment,C),g(es.$$.fragment,C),is=!1},d(C){C&&e(l),C&&e(L),z($,C),C&&e(M),C&&e(I),C&&e(F),z(N,C),C&&e(S),C&&e(Y),C&&e(K),z(es,C)}}}function yo(O){let l,d,p,h,y,j,v,P;return{c(){l=_("p"),d=n("\u270F\uFE0F "),p=_("strong"),h=n("\u8BD5\u8BD5\u770B!"),y=n(" \u9664\u4E86"),j=_("code"),v=n("TrainingArguments"),P=n(" \u4E4B\u5916\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u5927\u7EA630\u884C\u4EE3\u7801\u5C31\u53EF\u4EE5\u4ECE\u539F\u59CB\u6587\u672C\u5230\u8BAD\u7EC3GPT-2\u3002 \u7528\u4F60\u81EA\u5DF1\u7684\u6570\u636E\u96C6\u8BD5\u8BD5\u770B\uFF0C\u770B\u770B\u4F60\u80FD\u4E0D\u80FD\u5F97\u5230\u597D\u7684\u7ED3\u679C\uFF01")},l(w){l=c(w,"P",{});var D=u(l);d=r(D,"\u270F\uFE0F "),p=c(D,"STRONG",{});var G=u(p);h=r(G,"\u8BD5\u8BD5\u770B!"),G.forEach(e),y=r(D," \u9664\u4E86"),j=c(D,"CODE",{});var L=u(j);v=r(L,"TrainingArguments"),L.forEach(e),P=r(D," \u4E4B\u5916\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u5927\u7EA630\u884C\u4EE3\u7801\u5C31\u53EF\u4EE5\u4ECE\u539F\u59CB\u6587\u672C\u5230\u8BAD\u7EC3GPT-2\u3002 \u7528\u4F60\u81EA\u5DF1\u7684\u6570\u636E\u96C6\u8BD5\u8BD5\u770B\uFF0C\u770B\u770B\u4F60\u80FD\u4E0D\u80FD\u5F97\u5230\u597D\u7684\u7ED3\u679C\uFF01"),D.forEach(e)},m(w,D){o(w,l,D),t(l,d),t(l,p),t(p,h),t(l,y),t(l,j),t(j,v),t(l,P)},d(w){w&&e(l)}}}function vo(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M,I,R,A,B,W,F;return{c(){l=_("p"),d=n("\u{1F4A1} \u5982\u679C\u60A8\u6709\u6743\u8BBF\u95EE\u5177\u6709\u591A\u4E2A GPU \u7684\u8BA1\u7B97\u673A\uFF0C\u5219\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528 "),p=_("code"),h=n("MirroredStrategy"),y=n(" \u4E0A\u4E0B\u6587\u6765\u5927\u5E45\u52A0\u5FEB\u8BAD\u7EC3\u901F\u5EA6\u3002\u60A8\u9700\u8981\u521B\u5EFA\u4E00\u4E2A"),j=_("code"),v=n("tf.distribute.MirroredStrategy"),P=n("\u5BF9\u8C61\uFF0C\u5E76\u786E\u4FDD "),w=_("code"),D=n("to_tf_dataset"),G=n(" \u547D\u4EE4\u4EE5\u53CA\u6A21\u578B\u521B\u5EFA\u548C\u5BF9 "),L=_("code"),$=n("fit()"),M=n("\u7684\u8C03\u7528\u90FD\u5728\u5176 "),I=_("code"),R=n("scope()"),A=n(" context. \u4E0A\u4E0B\u6587\u4E2D\u8FD0\u884C\u3002\u60A8\u53EF\u4EE5\u67E5\u770B\u6709\u5173\u6B64\u5185\u5BB9\u7684\u6587\u6863"),B=_("a"),W=n("here"),F=n("."),this.h()},l(N){l=c(N,"P",{});var S=u(l);d=r(S,"\u{1F4A1} \u5982\u679C\u60A8\u6709\u6743\u8BBF\u95EE\u5177\u6709\u591A\u4E2A GPU \u7684\u8BA1\u7B97\u673A\uFF0C\u5219\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528 "),p=c(S,"CODE",{});var Y=u(p);h=r(Y,"MirroredStrategy"),Y.forEach(e),y=r(S," \u4E0A\u4E0B\u6587\u6765\u5927\u5E45\u52A0\u5FEB\u8BAD\u7EC3\u901F\u5EA6\u3002\u60A8\u9700\u8981\u521B\u5EFA\u4E00\u4E2A"),j=c(S,"CODE",{});var Z=u(j);v=r(Z,"tf.distribute.MirroredStrategy"),Z.forEach(e),P=r(S,"\u5BF9\u8C61\uFF0C\u5E76\u786E\u4FDD "),w=c(S,"CODE",{});var K=u(w);D=r(K,"to_tf_dataset"),K.forEach(e),G=r(S," \u547D\u4EE4\u4EE5\u53CA\u6A21\u578B\u521B\u5EFA\u548C\u5BF9 "),L=c(S,"CODE",{});var es=u(L);$=r(es,"fit()"),es.forEach(e),M=r(S,"\u7684\u8C03\u7528\u90FD\u5728\u5176 "),I=c(S,"CODE",{});var is=u(I);R=r(is,"scope()"),is.forEach(e),A=r(S," context. \u4E0A\u4E0B\u6587\u4E2D\u8FD0\u884C\u3002\u60A8\u53EF\u4EE5\u67E5\u770B\u6709\u5173\u6B64\u5185\u5BB9\u7684\u6587\u6863"),B=c(S,"A",{href:!0,rel:!0});var C=u(B);W=r(C,"here"),C.forEach(e),F=r(S,"."),S.forEach(e),this.h()},h(){H(B,"href","https://www.tensorflow.org/guide/distributed_training#use_tfdistributestrategy_with_keras_modelfit"),H(B,"rel","nofollow")},m(N,S){o(N,l,S),t(l,d),t(l,p),t(p,h),t(l,y),t(l,j),t(j,v),t(l,P),t(l,w),t(w,D),t(l,G),t(l,L),t(L,$),t(l,M),t(l,I),t(I,R),t(l,A),t(l,B),t(B,W),t(l,F)},d(N){N&&e(l)}}}function qo(O){let l,d,p,h,y;return{c(){l=_("p"),d=n("\u{1F4A1} \u5982\u679C\u60A8\u53EF\u4EE5\u8BBF\u95EE\u5177\u6709\u591A\u4E2A GPU \u7684\u673A\u5668\uFF0C\u8BF7\u5C1D\u8BD5\u5728\u90A3\u91CC\u8FD0\u884C\u4EE3\u7801\u3002 "),p=_("code"),h=n("Trainer"),y=n("\u81EA\u52A8\u7BA1\u7406\u591A\u53F0\u673A\u5668\uFF0C\u8FD9\u53EF\u4EE5\u6781\u5927\u5730\u52A0\u5FEB\u8BAD\u7EC3\u901F\u5EA6\u3002")},l(j){l=c(j,"P",{});var v=u(l);d=r(v,"\u{1F4A1} \u5982\u679C\u60A8\u53EF\u4EE5\u8BBF\u95EE\u5177\u6709\u591A\u4E2A GPU \u7684\u673A\u5668\uFF0C\u8BF7\u5C1D\u8BD5\u5728\u90A3\u91CC\u8FD0\u884C\u4EE3\u7801\u3002 "),p=c(v,"CODE",{});var P=u(p);h=r(P,"Trainer"),P.forEach(e),y=r(v,"\u81EA\u52A8\u7BA1\u7406\u591A\u53F0\u673A\u5668\uFF0C\u8FD9\u53EF\u4EE5\u6781\u5927\u5730\u52A0\u5FEB\u8BAD\u7EC3\u901F\u5EA6\u3002"),v.forEach(e)},m(j,v){o(j,l,v),t(l,d),t(l,p),t(p,h),t(l,y)},d(j){j&&e(l)}}}function Eo(O){let l;function d(y,j){return y[0]==="pt"?qo:vo}let p=d(O),h=p(O);return{c(){h.c(),l=qn()},l(y){h.l(y),l=qn()},m(y,j){h.m(y,j),o(y,l,j)},p(y,j){p!==(p=d(y))&&(h.d(1),h=p(y),h&&(h.c(),h.m(l.parentNode,l)))},d(y){h.d(y),y&&e(l)}}}function xo(O){let l,d;return l=new T({props:{code:`from transformers import pipeline

course_model = TFGPT2LMHeadModel.from_pretrained("huggingface-course/codeparrot-ds")
course_tokenizer = AutoTokenizer.from_pretrained("huggingface-course/codeparrot-ds")
pipe = pipeline(
    "text-generation", model=course_model, tokenizer=course_tokenizer, device=0
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

course_model = TFGPT2LMHeadModel.from_pretrained(<span class="hljs-string">&quot;huggingface-course/codeparrot-ds&quot;</span>)
course_tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;huggingface-course/codeparrot-ds&quot;</span>)
pipe = pipeline(
    <span class="hljs-string">&quot;text-generation&quot;</span>, model=course_model, tokenizer=course_tokenizer, device=<span class="hljs-number">0</span>
)`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function zo(O){let l,d;return l=new T({props:{code:`import torch
from transformers import pipeline

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
pipe = pipeline(
    "text-generation", model="huggingface-course/codeparrot-ds", device=device
)`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
pipe = pipeline(
    <span class="hljs-string">&quot;text-generation&quot;</span>, model=<span class="hljs-string">&quot;huggingface-course/codeparrot-ds&quot;</span>, device=device
)`}}),{c(){q(l.$$.fragment)},l(p){E(l.$$.fragment,p)},m(p,h){x(l,p,h),d=!0},i(p){d||(b(l.$$.fragment,p),d=!0)},o(p){g(l.$$.fragment,p),d=!1},d(p){z(l,p)}}}function Po(O){let l,d,p,h,y;return{c(){l=_("p"),d=n("\u4ECE\u8FD9\u51E0\u4E2A\u4F8B\u5B50\u6765\u770B\uFF0C\u6A21\u578B\u4F3C\u4E4E\u5DF2\u7ECF\u5B66\u4E60\u4E86 Python \u6570\u636E\u79D1\u5B66\u5806\u6808\u7684\u4E00\u4E9B\u8BED\u6CD5\uFF08\u5F53\u7136\uFF0C\u5728\u5C06\u6A21\u578B\u90E8\u7F72\u5230\u73B0\u5B9E\u4E16\u754C\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5BF9\u5176\u8FDB\u884C\u66F4\u5168\u9762\u7684\u8BC4\u4F30\uFF09\u3002\u7136\u800C\uFF0C\u6709\u65F6\u9700\u8981\u5BF9\u6A21\u578B\u8BAD\u7EC3\u8FDB\u884C\u66F4\u591A\u5B9A\u5236\u624D\u80FD\u5B9E\u73B0\u7ED9\u5B9A\u7528\u4F8B\u7684\u5FC5\u8981\u6027\u80FD\u3002\u4F8B\u5982\uFF0C\u5982\u679C\u6211\u4EEC\u60F3\u52A8\u6001\u66F4\u65B0\u6279\u91CF\u5927\u5C0F\u6216\u6709\u4E00\u4E2A\u6761\u4EF6\u8BAD\u7EC3\u5FAA\u73AF\u6765\u5373\u65F6\u8DF3\u8FC7\u574F\u793A\u4F8B\u600E\u4E48\u529E\uFF1F\u4E00\u79CD\u9009\u62E9\u662F\u5C06 "),p=_("code"),h=n("Trainer"),y=n(" \u5E76\u6DFB\u52A0\u5FC5\u8981\u7684\u66F4\u6539\uFF0C\u4F46\u6709\u65F6\u4ECE\u5934\u5F00\u59CB\u7F16\u5199\u8BAD\u7EC3\u5FAA\u73AF\u4F1A\u66F4\u7B80\u5355\u3002\u8FD9\u5C31\u662F\u{1F917} Accelerate \u7684\u7528\u6B66\u4E4B\u5730\u3002")},l(j){l=c(j,"P",{});var v=u(l);d=r(v,"\u4ECE\u8FD9\u51E0\u4E2A\u4F8B\u5B50\u6765\u770B\uFF0C\u6A21\u578B\u4F3C\u4E4E\u5DF2\u7ECF\u5B66\u4E60\u4E86 Python \u6570\u636E\u79D1\u5B66\u5806\u6808\u7684\u4E00\u4E9B\u8BED\u6CD5\uFF08\u5F53\u7136\uFF0C\u5728\u5C06\u6A21\u578B\u90E8\u7F72\u5230\u73B0\u5B9E\u4E16\u754C\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5BF9\u5176\u8FDB\u884C\u66F4\u5168\u9762\u7684\u8BC4\u4F30\uFF09\u3002\u7136\u800C\uFF0C\u6709\u65F6\u9700\u8981\u5BF9\u6A21\u578B\u8BAD\u7EC3\u8FDB\u884C\u66F4\u591A\u5B9A\u5236\u624D\u80FD\u5B9E\u73B0\u7ED9\u5B9A\u7528\u4F8B\u7684\u5FC5\u8981\u6027\u80FD\u3002\u4F8B\u5982\uFF0C\u5982\u679C\u6211\u4EEC\u60F3\u52A8\u6001\u66F4\u65B0\u6279\u91CF\u5927\u5C0F\u6216\u6709\u4E00\u4E2A\u6761\u4EF6\u8BAD\u7EC3\u5FAA\u73AF\u6765\u5373\u65F6\u8DF3\u8FC7\u574F\u793A\u4F8B\u600E\u4E48\u529E\uFF1F\u4E00\u79CD\u9009\u62E9\u662F\u5C06 "),p=c(v,"CODE",{});var P=u(p);h=r(P,"Trainer"),P.forEach(e),y=r(v," \u5E76\u6DFB\u52A0\u5FC5\u8981\u7684\u66F4\u6539\uFF0C\u4F46\u6709\u65F6\u4ECE\u5934\u5F00\u59CB\u7F16\u5199\u8BAD\u7EC3\u5FAA\u73AF\u4F1A\u66F4\u7B80\u5355\u3002\u8FD9\u5C31\u662F\u{1F917} Accelerate \u7684\u7528\u6B66\u4E4B\u5730\u3002"),v.forEach(e)},m(j,v){o(j,l,v),t(l,d),t(l,p),t(p,h),t(l,y)},d(j){j&&e(l)}}}function To(O){let l,d;return{c(){l=_("p"),d=n("\u770B\u770B\u8FD9\u51E0\u4E2A\u4F8B\u5B50\uFF0C\u4F3C\u4E4E\u6A21\u578B\u5DF2\u7ECF\u5B66\u4E60\u4E86Python\u6570\u636E\u79D1\u5B66\u5806\u6808\u7684\u4E00\u4E9B\u8BED\u6CD5\u3002\u5F53\u7136\uFF0C\u5728\u5C06\u6A21\u578B\u90E8\u7F72\u5230\u73B0\u5B9E\u4E16\u754C\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u66F4\u5F7B\u5E95\u5730\u8BC4\u4F30\u6A21\u578B\uFF0C\u4F46\u8FD9\u4ECD\u7136\u662F\u4E00\u4E2A\u4EE4\u4EBA\u5370\u8C61\u6DF1\u523B\u7684\u539F\u578B\u3002")},l(p){l=c(p,"P",{});var h=u(l);d=r(h,"\u770B\u770B\u8FD9\u51E0\u4E2A\u4F8B\u5B50\uFF0C\u4F3C\u4E4E\u6A21\u578B\u5DF2\u7ECF\u5B66\u4E60\u4E86Python\u6570\u636E\u79D1\u5B66\u5806\u6808\u7684\u4E00\u4E9B\u8BED\u6CD5\u3002\u5F53\u7136\uFF0C\u5728\u5C06\u6A21\u578B\u90E8\u7F72\u5230\u73B0\u5B9E\u4E16\u754C\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u66F4\u5F7B\u5E95\u5730\u8BC4\u4F30\u6A21\u578B\uFF0C\u4F46\u8FD9\u4ECD\u7136\u662F\u4E00\u4E2A\u4EE4\u4EBA\u5370\u8C61\u6DF1\u523B\u7684\u539F\u578B\u3002"),h.forEach(e)},m(p,h){o(p,l,h),t(l,d)},d(p){p&&e(l)}}}function so(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M,I,R,A,B,W,F,N,S,Y,Z,K,es,is,C,U,Pe,qs,hs,Es,J,Te,De,tt,pa,at,lt,ia,bt,ts,Ce,nt,V,_a,Qs,Gs,gt,_s,kt,Oe,jt,Ms,$s,Ae,ns,ca,xs,ua,ma,se,fa,wt,as,da,rt,yt,Fs,ot,pt,ha,vt,Ls,Hs,ee,Ge,qt,Is,Ns,te,ae,it,bs,Et,cs,le,Me,Fe,$a,ne,re,xt,Ss,Rs,oe,Le,zt,Bs,Us,Ws,pe,Xs,_t,gs,Pt,Ks,Vs,us,ie,He,Ys,ba,_e,ga,ka,ct,ms,Tt,ls,ce,Ie,Ne,ja,Se,rs,wa,ue,ya,va,me,fe,Dt,zs,Ct,Re,Ot,ks,fs,qa,js,de,At,Gt,Be,ut,Mt,he,mt,ds,ft,os,Ft,ws,Ea,dt,Lt,ps,Ht,Ps,It,Ue,We,Nt,$e,Xe,be,St;return h=new oo({}),I=new Vn({props:{id:"Hm8_PgVTFuc"}}),Ce=new T({props:{code:`keytoken_ids = []
for keyword in [
    "plt",
    "pd",
    "sk",
    "fit",
    "predict",
    " plt",
    " pd",
    " sk",
    " fit",
    " predict",
    "testtest",
]:
    ids = tokenizer([keyword]).input_ids[0]
    if len(ids) == 1:
        keytoken_ids.append(ids[0])
    else:
        print(f"Keyword has not single token: {keyword}")`,highlighted:`keytoken_ids = []
<span class="hljs-keyword">for</span> keyword <span class="hljs-keyword">in</span> [
    <span class="hljs-string">&quot;plt&quot;</span>,
    <span class="hljs-string">&quot;pd&quot;</span>,
    <span class="hljs-string">&quot;sk&quot;</span>,
    <span class="hljs-string">&quot;fit&quot;</span>,
    <span class="hljs-string">&quot;predict&quot;</span>,
    <span class="hljs-string">&quot; plt&quot;</span>,
    <span class="hljs-string">&quot; pd&quot;</span>,
    <span class="hljs-string">&quot; sk&quot;</span>,
    <span class="hljs-string">&quot; fit&quot;</span>,
    <span class="hljs-string">&quot; predict&quot;</span>,
    <span class="hljs-string">&quot;testtest&quot;</span>,
]:
    ids = tokenizer([keyword]).input_ids[<span class="hljs-number">0</span>]
    <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(ids) == <span class="hljs-number">1</span>:
        keytoken_ids.append(ids[<span class="hljs-number">0</span>])
    <span class="hljs-keyword">else</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Keyword has not single token: <span class="hljs-subst">{keyword}</span>&quot;</span>)`}}),V=new T({props:{code:"'Keyword has not single token: testtest'",highlighted:'<span class="hljs-string">&#x27;Keyword has not single token: testtest&#x27;</span>'}}),_s=new T({props:{code:`from torch.nn import CrossEntropyLoss
import torch


def keytoken_weighted_loss(inputs, logits, keytoken_ids, alpha=1.0):
    # Shift so that tokens < n predict n
    shift_labels = inputs[..., 1:].contiguous()
    shift_logits = logits[..., :-1, :].contiguous()
    # Calculate per-token loss
    loss_fct = CrossEntropyLoss(reduce=False)
    loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
    # Resize and average loss per sample
    loss_per_sample = loss.view(shift_logits.size(0), shift_logits.size(1)).mean(axis=1)
    # Calculate and scale weighting
    weights = torch.stack([(inputs == kt).float() for kt in keytoken_ids]).sum(
        axis=[0, 2]
    )
    weights = alpha * (1.0 + weights)
    # Calculate weighted average
    weighted_loss = (loss_per_sample * weights).mean()
    return weighted_loss`,highlighted:`<span class="hljs-keyword">from</span> torch.nn <span class="hljs-keyword">import</span> CrossEntropyLoss
<span class="hljs-keyword">import</span> torch


<span class="hljs-keyword">def</span> <span class="hljs-title function_">keytoken_weighted_loss</span>(<span class="hljs-params">inputs, logits, keytoken_ids, alpha=<span class="hljs-number">1.0</span></span>):
    <span class="hljs-comment"># Shift so that tokens &lt; n predict n</span>
    shift_labels = inputs[..., <span class="hljs-number">1</span>:].contiguous()
    shift_logits = logits[..., :-<span class="hljs-number">1</span>, :].contiguous()
    <span class="hljs-comment"># Calculate per-token loss</span>
    loss_fct = CrossEntropyLoss(reduce=<span class="hljs-literal">False</span>)
    loss = loss_fct(shift_logits.view(-<span class="hljs-number">1</span>, shift_logits.size(-<span class="hljs-number">1</span>)), shift_labels.view(-<span class="hljs-number">1</span>))
    <span class="hljs-comment"># Resize and average loss per sample</span>
    loss_per_sample = loss.view(shift_logits.size(<span class="hljs-number">0</span>), shift_logits.size(<span class="hljs-number">1</span>)).mean(axis=<span class="hljs-number">1</span>)
    <span class="hljs-comment"># Calculate and scale weighting</span>
    weights = torch.stack([(inputs == kt).<span class="hljs-built_in">float</span>() <span class="hljs-keyword">for</span> kt <span class="hljs-keyword">in</span> keytoken_ids]).<span class="hljs-built_in">sum</span>(
        axis=[<span class="hljs-number">0</span>, <span class="hljs-number">2</span>]
    )
    weights = alpha * (<span class="hljs-number">1.0</span> + weights)
    <span class="hljs-comment"># Calculate weighted average</span>
    weighted_loss = (loss_per_sample * weights).mean()
    <span class="hljs-keyword">return</span> weighted_loss`}}),Ls=new T({props:{code:`from torch.utils.data.dataloader import DataLoader

tokenized_dataset.set_format("torch")
train_dataloader = DataLoader(tokenized_dataset["train"], batch_size=32, shuffle=True)
eval_dataloader = DataLoader(tokenized_dataset["valid"], batch_size=32)`,highlighted:`<span class="hljs-keyword">from</span> torch.utils.data.dataloader <span class="hljs-keyword">import</span> DataLoader

tokenized_dataset.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
train_dataloader = DataLoader(tokenized_dataset[<span class="hljs-string">&quot;train&quot;</span>], batch_size=<span class="hljs-number">32</span>, shuffle=<span class="hljs-literal">True</span>)
eval_dataloader = DataLoader(tokenized_dataset[<span class="hljs-string">&quot;valid&quot;</span>], batch_size=<span class="hljs-number">32</span>)`}}),Is=new T({props:{code:`weight_decay = 0.1


def get_grouped_params(model, no_decay=["bias", "LayerNorm.weight"]):
    params_with_wd, params_without_wd = [], []
    for n, p in model.named_parameters():
        if any(nd in n for nd in no_decay):
            params_without_wd.append(p)
        else:
            params_with_wd.append(p)
    return [
        {"params": params_with_wd, "weight_decay": weight_decay},
        {"params": params_without_wd, "weight_decay": 0.0},
    ]`,highlighted:`weight_decay = <span class="hljs-number">0.1</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_grouped_params</span>(<span class="hljs-params">model, no_decay=[<span class="hljs-string">&quot;bias&quot;</span>, <span class="hljs-string">&quot;LayerNorm.weight&quot;</span>]</span>):
    params_with_wd, params_without_wd = [], []
    <span class="hljs-keyword">for</span> n, p <span class="hljs-keyword">in</span> model.named_parameters():
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">any</span>(nd <span class="hljs-keyword">in</span> n <span class="hljs-keyword">for</span> nd <span class="hljs-keyword">in</span> no_decay):
            params_without_wd.append(p)
        <span class="hljs-keyword">else</span>:
            params_with_wd.append(p)
    <span class="hljs-keyword">return</span> [
        {<span class="hljs-string">&quot;params&quot;</span>: params_with_wd, <span class="hljs-string">&quot;weight_decay&quot;</span>: weight_decay},
        {<span class="hljs-string">&quot;params&quot;</span>: params_without_wd, <span class="hljs-string">&quot;weight_decay&quot;</span>: <span class="hljs-number">0.0</span>},
    ]`}}),bs=new T({props:{code:`def evaluate():
    model.eval()
    losses = []
    for step, batch in enumerate(eval_dataloader):
        with torch.no_grad():
            outputs = model(batch["input_ids"], labels=batch["input_ids"])

        losses.append(accelerator.gather(outputs.loss))
    loss = torch.mean(torch.cat(losses))
    try:
        perplexity = torch.exp(loss)
    except OverflowError:
        perplexity = float("inf")
    return loss.item(), perplexity.item()`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">evaluate</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[<span class="hljs-string">&quot;input_ids&quot;</span>], labels=batch[<span class="hljs-string">&quot;input_ids&quot;</span>])

        losses.append(accelerator.gather(outputs.loss))
    loss = torch.mean(torch.cat(losses))
    <span class="hljs-keyword">try</span>:
        perplexity = torch.exp(loss)
    <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-keyword">return</span> loss.item(), perplexity.item()`}}),Rs=new T({props:{code:"model = GPT2LMHeadModel(config)",highlighted:"model = GPT2LMHeadModel(config)"}}),Us=new T({props:{code:`from torch.optim import AdamW

optimizer = AdamW(get_grouped_params(model), lr=5e-4)`,highlighted:`<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(get_grouped_params(model), lr=<span class="hljs-number">5e-4</span>)`}}),gs=new T({props:{code:`from accelerate import Accelerator

accelerator = Accelerator(fp16=True)

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(fp16=<span class="hljs-literal">True</span>)

model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`}}),Ks=new oa({props:{$$slots:{default:[Do]},$$scope:{ctx:O}}}),ms=new T({props:{code:`num_train_epochs = 1
num_update_steps_per_epoch = len(train_dataloader)
num_training_steps = num_train_epochs * num_update_steps_per_epoch

lr_scheduler = get_scheduler(
    name="linear",
    optimizer=optimizer,
    num_warmup_steps=1_000,
    num_training_steps=num_training_steps,
)`,highlighted:`num_train_epochs = <span class="hljs-number">1</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(
    name=<span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">1_000</span>,
    num_training_steps=num_training_steps,
)`}}),fe=new T({props:{code:`from huggingface_hub import Repository, get_full_repo_name

model_name = "codeparrot-ds-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> Repository, get_full_repo_name

model_name = <span class="hljs-string">&quot;codeparrot-ds-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`}}),zs=new T({props:{code:"'sgugger/codeparrot-ds-accelerate'",highlighted:'<span class="hljs-string">&#x27;sgugger/codeparrot-ds-accelerate&#x27;</span>'}}),fs=new T({props:{code:`output_dir = "codeparrot-ds-accelerate"
repo = Repository(output_dir, clone_from=repo_name)`,highlighted:`output_dir = <span class="hljs-string">&quot;codeparrot-ds-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`}}),ds=new T({props:{code:"evaluate()",highlighted:"evaluate()"}}),os=new T({props:{code:"(10.934126853942871, 56057.14453125)",highlighted:'(<span class="hljs-number">10.934126853942871</span>, <span class="hljs-number">56057.14453125</span>)'}}),Ps=new T({props:{code:`from tqdm.notebook import tqdm

gradient_accumulation_steps = 8
eval_steps = 5_000

model.train()
completed_steps = 0
for epoch in range(num_train_epochs):
    for step, batch in tqdm(
        enumerate(train_dataloader, start=1), total=len(train_dataloader)
    ):
        logits = model(batch["input_ids"]).logits
        loss = keytoken_weighted_loss(batch["input_ids"], logits, keytoken_ids)
        if step % 100 == 0:
            accelerator.print(
                {
                    "lr": get_lr(),
                    "samples": step * samples_per_step,
                    "steps": completed_steps,
                    "loss/train": loss.item() * gradient_accumulation_steps,
                }
            )
        loss = loss / gradient_accumulation_steps
        accelerator.backward(loss)
        if step % gradient_accumulation_steps == 0:
            accelerator.clip_grad_norm_(model.parameters(), 1.0)
            optimizer.step()
            lr_scheduler.step()
            optimizer.zero_grad()
            completed_steps += 1
        if (step % (eval_steps * gradient_accumulation_steps)) == 0:
            eval_loss, perplexity = evaluate()
            accelerator.print({"loss/eval": eval_loss, "perplexity": perplexity})
            model.train()
            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 step {step}", blocking=False
                )`,highlighted:`<span class="hljs-keyword">from</span> tqdm.notebook <span class="hljs-keyword">import</span> tqdm

gradient_accumulation_steps = <span class="hljs-number">8</span>
eval_steps = <span class="hljs-number">5_000</span>

model.train()
completed_steps = <span class="hljs-number">0</span>
<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-keyword">for</span> step, batch <span class="hljs-keyword">in</span> tqdm(
        <span class="hljs-built_in">enumerate</span>(train_dataloader, start=<span class="hljs-number">1</span>), total=<span class="hljs-built_in">len</span>(train_dataloader)
    ):
        logits = model(batch[<span class="hljs-string">&quot;input_ids&quot;</span>]).logits
        loss = keytoken_weighted_loss(batch[<span class="hljs-string">&quot;input_ids&quot;</span>], logits, keytoken_ids)
        <span class="hljs-keyword">if</span> step % <span class="hljs-number">100</span> == <span class="hljs-number">0</span>:
            accelerator.<span class="hljs-built_in">print</span>(
                {
                    <span class="hljs-string">&quot;lr&quot;</span>: get_lr(),
                    <span class="hljs-string">&quot;samples&quot;</span>: step * samples_per_step,
                    <span class="hljs-string">&quot;steps&quot;</span>: completed_steps,
                    <span class="hljs-string">&quot;loss/train&quot;</span>: loss.item() * gradient_accumulation_steps,
                }
            )
        loss = loss / gradient_accumulation_steps
        accelerator.backward(loss)
        <span class="hljs-keyword">if</span> step % gradient_accumulation_steps == <span class="hljs-number">0</span>:
            accelerator.clip_grad_norm_(model.parameters(), <span class="hljs-number">1.0</span>)
            optimizer.step()
            lr_scheduler.step()
            optimizer.zero_grad()
            completed_steps += <span class="hljs-number">1</span>
        <span class="hljs-keyword">if</span> (step % (eval_steps * gradient_accumulation_steps)) == <span class="hljs-number">0</span>:
            eval_loss, perplexity = evaluate()
            accelerator.<span class="hljs-built_in">print</span>({<span class="hljs-string">&quot;loss/eval&quot;</span>: eval_loss, <span class="hljs-string">&quot;perplexity&quot;</span>: perplexity})
            model.train()
            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 step <span class="hljs-subst">{step}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
                )`}}),$e=new oa({props:{$$slots:{default:[Co]},$$scope:{ctx:O}}}),be=new oa({props:{$$slots:{default:[Oo]},$$scope:{ctx:O}}}),{c(){l=_("h2"),d=_("a"),p=_("span"),q(h.$$.fragment),y=m(),j=_("span"),v=n("\u7528 \u{1F917} Accelerate \u8BAD\u7EC3"),P=m(),w=_("p"),D=n("\u6211\u4EEC\u5DF2\u7ECF\u770B\u5230\u4E86\u5982\u4F55\u4F7F\u7528 "),G=_("code"),L=n("Trainer"),$=n(" \uFF0C\u8FD9\u53EF\u4EE5\u5141\u8BB8\u4E00\u4E9B\u81EA\u5B9A\u4E49\u3002\u7136\u800C\uFF0C\u6709\u65F6\u6211\u4EEC\u60F3\u8981\u5B8C\u5168\u63A7\u5236\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u6216\u8005\u6211\u4EEC\u60F3\u8981\u8FDB\u884C\u4E00\u4E9B\u5947\u7279\u7684\u66F4\u6539\u3002\u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B \u{1F917} Accelerate \u662F\u4E00\u4E2A\u4E0D\u9519\u7684\u9009\u62E9\uFF0C\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u9010\u6B65\u4ECB\u7ECD\u4F7F\u7528\u5B83\u6765\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u7684\u6B65\u9AA4\u3002\u4E3A\u4E86\u8BA9\u4E8B\u60C5\u53D8\u5F97\u66F4\u6709\u8DA3\uFF0C\u6211\u4EEC\u8FD8\u5C06\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\u6DFB\u52A0\u4E00\u4E9B\u4FEE\u6539\u3002"),M=m(),q(I.$$.fragment),R=m(),A=_("p"),B=n("\u7531\u4E8E\u6211\u4EEC\u4E3B\u8981\u5BF9\u6570\u636E\u79D1\u5B66\u5E93\u7684\u5408\u7406\u81EA\u52A8\u586B\u5145\u611F\u5174\u8DA3\uFF0C\u56E0\u6B64\u5BF9\u66F4\u591A\u4F7F\u7528\u8FD9\u4E9B\u5E93\u7684\u8BAD\u7EC3\u6837\u672C\u7ED9\u4E88\u66F4\u591A\u6743\u91CD\u662F\u6709\u610F\u4E49\u7684\u3002\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u4F7F\u7528\u5173\u952E\u5B57\u8F7B\u677E\u8BC6\u522B\u8FD9\u4E9B\u793A\u4F8B\uFF0C\u4F8B\u5982 "),W=_("code"),F=n("plt"),N=n("\u3001"),S=_("code"),Y=n("pd"),Z=n("\u3001"),K=_("code"),es=n("sk"),is=n("\u3001"),C=_("code"),U=n("fit"),Pe=n("\u548C"),qs=_("code"),hs=n("predict"),Es=n("\u7B49\u5173\u952E\u5B57\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5F88\u5BB9\u6613\u5730\u8BC6\u522B\u8FD9\u4E9B\u793A\u4F8B\uFF0C\u8FD9\u4E9B\u5173\u952E\u5B57\u662Fmatplotlib\u6700\u5E38\u7528\u7684\u5BFC\u5165\u540D\u79F0\u3002"),J=_("code"),Te=n("Pyplot"),De=n(", "),tt=_("code"),pa=n("pandas"),at=n("\u548C"),lt=_("code"),ia=n("sklearn"),bt=n("\u4EE5\u53CA\u540E\u8005\u7684\u62DF\u5408/\u9884\u6D4B\u6A21\u5F0F\u3002\u5982\u679C\u8FD9\u4E9B\u90FD\u8868\u793A\u4E3A\u5355\u4E2A\u6807\u8BB0\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u68C0\u67E5\u5B83\u4EEC\u662F\u5426\u51FA\u73B0\u5728\u8F93\u5165\u5E8F\u5217\u4E2D\u3002\u6807\u8BB0\u53EF\u80FD\u6709\u4E00\u4E2A\u7A7A\u683C\u524D\u7F00\uFF0C\u56E0\u6B64\u6211\u4EEC\u8FD8\u5C06\u5728\u6807\u8BB0\u5668\u8BCD\u6C47\u8868\u4E2D\u68C0\u67E5\u8FD9\u4E9B\u7248\u672C\u3002\u4E3A\u4E86\u9A8C\u8BC1\u5B83\u662F\u5426\u6709\u6548\uFF0C\u6211\u4EEC\u5C06\u6DFB\u52A0\u4E00\u4E2A\u6D4B\u8BD5token \uFF0C\u8BE5token \u5E94\u62C6\u5206\u4E3A\u591A\u4E2Atokens\uFF1A"),ts=m(),q(Ce.$$.fragment),nt=m(),q(V.$$.fragment),_a=m(),Qs=_("p"),Gs=n("\u592A\u597D\u4E86\uFF0C\u8FD9\u4F3C\u4E4E\u5F88\u597D\u7528\uFF01\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u7F16\u5199\u4E00\u4E2A\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\uFF0C\u5B83\u5C06\u8F93\u5165\u5E8F\u5217\u3001logits \u548C\u6211\u4EEC\u521A\u521A\u9009\u62E9\u7684\u5173\u200B\u200B\u952E\u6807\u8BB0\u4F5C\u4E3A\u8F93\u5165\u3002\u9996\u5148\uFF0C\u6211\u4EEC\u9700\u8981\u5BF9\u9F50 logits \u548C\u8F93\u5165\uFF1A\u5411\u53F3\u79FB\u52A8\u4E00\u4E2A\u7684\u8F93\u5165\u5E8F\u5217\u5F62\u6210\u6807\u7B7E\uFF0C\u56E0\u4E3A\u4E0B\u4E00\u4E2A\u6807\u8BB0\u662F\u5F53\u524D\u6807\u8BB0\u7684\u6807\u7B7E\u3002\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u4ECE\u8F93\u5165\u5E8F\u5217\u7684\u7B2C\u4E8C\u4E2A\u6807\u8BB0\u5F00\u59CB\u6807\u8BB0\u6765\u5B9E\u73B0\u8FD9\u4E00\u70B9\uFF0C\u56E0\u4E3A\u6A21\u578B\u65E0\u8BBA\u5982\u4F55\u90FD\u4E0D\u4F1A\u5BF9\u7B2C\u4E00\u4E2A\u6807\u8BB0\u8FDB\u884C\u9884\u6D4B\u3002\u7136\u540E\u6211\u4EEC\u5207\u65AD\u6700\u540E\u4E00\u4E2A logit\uFF0C\u56E0\u4E3A\u6211\u4EEC\u6CA1\u6709\u5B8C\u6574\u8F93\u5165\u5E8F\u5217\u4E4B\u540E\u7684\u6807\u8BB0\u7684\u6807\u7B7E\u3002\u6709\u4E86\u8FD9\u4E2A\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8BA1\u7B97\u6BCF\u4E2A\u6837\u672C\u7684\u635F\u5931\u5E76\u8BA1\u7B97\u6BCF\u4E2A\u6837\u672C\u4E2D\u6240\u6709\u5173\u952E\u5B57\u7684\u51FA\u73B0\u6B21\u6570\u3002\u6700\u540E\uFF0C\u6211\u4EEC\u4F7F\u7528\u51FA\u73B0\u6B21\u6570\u4F5C\u4E3A\u6743\u91CD\u8BA1\u7B97\u6240\u6709\u6837\u672C\u7684\u52A0\u6743\u5E73\u5747\u503C\u3002\u7531\u4E8E\u6211\u4EEC\u4E0D\u60F3\u6254\u6389\u6240\u6709\u6CA1\u6709\u5173\u952E\u5B57\u7684\u6837\u672C\uFF0C\u6211\u4EEC\u5C06\u6743\u91CD\u52A01\uFF1A"),gt=m(),q(_s.$$.fragment),kt=m(),Oe=_("p"),jt=n("\u5728\u6211\u4EEC\u5F00\u59CB\u4F7F\u7528\u8FD9\u4E2A\u5F88\u68D2\u7684\u65B0\u635F\u5931\u51FD\u6570\u8FDB\u884C\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u51C6\u5907\u4E00\u4E9B\u4E1C\u897F\uFF1A"),Ms=m(),$s=_("ul"),Ae=_("li"),ns=n("\u6211\u4EEC\u9700\u8981\u6570\u636E\u52A0\u8F7D\u5668\u6765\u6279\u91CF\u52A0\u8F7D\u6570\u636E\u3002"),ca=m(),xs=_("li"),ua=n("\u6211\u4EEC\u9700\u8981\u8BBE\u7F6E\u6743\u91CD\u8870\u51CF\u53C2\u6570\u3002"),ma=m(),se=_("li"),fa=n("\u6709\u65F6\u6211\u4EEC\u60F3\u8981\u6C42\u503C\uFF0C\u56E0\u6B64\u5C06\u6C42\u503C\u4EE3\u7801\u5305\u88C5\u5728\u4E00\u4E2A\u51FD\u6570\u4E2D\u662F\u6709\u610F\u4E49\u7684\u3002"),wt=m(),as=_("p"),da=n("\u8BA9\u6211\u4EEC\u4ECE\u6570\u636E\u52A0\u8F7D\u5668\u5F00\u59CB\u3002\u6211\u4EEC\u53EA\u9700\u8981\u5C06\u6570\u636E\u96C6\u7684\u683C\u5F0F\u8BBE\u7F6E\u4E3A "),rt=_("code"),yt=n('"torch"'),Fs=n("\uFF0C\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4F20\u9012\u7ED9 PyTorch "),ot=_("code"),pt=n("DataLoader"),ha=n(" ,\u540C\u65F6\u8BBE\u7F6E\u9002\u5F53\u7684\u6279\u91CF\u5927\u5C0F\uFF1A"),vt=m(),q(Ls.$$.fragment),Hs=m(),ee=_("p"),Ge=n("\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u5BF9\u53C2\u6570\u8FDB\u884C\u5206\u7EC4\uFF0C\u4EE5\u4FBF\u4F18\u5316\u5668\u77E5\u9053\u54EA\u4E9B\u5C06\u83B7\u5F97\u989D\u5916\u7684\u6743\u91CD\u8870\u51CF\u3002\u901A\u5E38\uFF0C\u6240\u6709\u504F\u5DEE\u548C LayerNorm \u6743\u91CD\u9879\u90FD\u4E0D\u53D7\u6B64\u9650\u5236\uFF1B\u4EE5\u4E0B\u6211\u4EEC\u5982\u4F55\u505A\u5230\u8FD9\u4E00\u70B9\uFF1A"),qt=m(),q(Is.$$.fragment),Ns=m(),te=_("p"),ae=n("\u7531\u4E8E\u6211\u4EEC\u5E0C\u671B\u5728\u8BAD\u7EC3\u671F\u95F4\u5B9A\u671F\u5728\u9A8C\u8BC1\u96C6\u4E0A\u8BC4\u4F30\u6A21\u578B\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E5F\u4E3A\u6B64\u7F16\u5199\u4E00\u4E2A\u51FD\u6570\u3002\u5B83\u53EA\u662F\u8FD0\u884C\u8BC4\u4F30\u6570\u636E\u52A0\u8F7D\u5668\u5E76\u6536\u96C6\u8DE8\u8FDB\u7A0B\u7684\u6240\u6709\u635F\u5931\uFF1A"),it=m(),q(bs.$$.fragment),Et=m(),cs=_("p"),le=n("\u901A\u8FC7 "),Me=_("code"),Fe=n("evaluate()"),$a=n(" \u51FD\u6570\u6211\u4EEC\u5B9A\u671F\u53EF\u4EE5\u83B7\u53D6\u635F\u5931\u503C\u548C"),ne=_("a"),re=n("perplexity"),xt=n("\u3002\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u91CD\u65B0\u5B9A\u4E49\u6211\u4EEC\u7684\u6A21\u578B\u4EE5\u786E\u4FDD\u6211\u4EEC\u518D\u6B21\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\uFF1A"),Ss=m(),q(Rs.$$.fragment),oe=m(),Le=_("p"),zt=n("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5B9A\u4E49\u6211\u4EEC\u7684\u4F18\u5316\u5668\uFF0C\u4F7F\u7528\u4E4B\u524D\u7684\u51FD\u6570\u6765\u5206\u5272\u6743\u91CD\u8870\u51CF\u7684\u53C2\u6570\uFF1A"),Bs=m(),q(Us.$$.fragment),Ws=m(),pe=_("p"),Xs=n("\u73B0\u5728\u8BA9\u6211\u4EEC\u51C6\u5907\u6A21\u578B\u3001\u4F18\u5316\u5668\u548C\u6570\u636E\u52A0\u8F7D\u5668\uFF0C\u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u5F00\u59CB\u8BAD\u7EC3\uFF1A"),_t=m(),q(gs.$$.fragment),Pt=m(),q(Ks.$$.fragment),Vs=m(),us=_("p"),ie=n("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u53D1\u9001\u4E86\u6211\u4EEC\u7684 "),He=_("code"),Ys=n("train_dataloader"),ba=n("\u5230 "),_e=_("code"),ga=n("accelerator.prepare()"),ka=n(" \uFF0C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u5B83\u7684\u957F\u5EA6\u6765\u8BA1\u7B97\u8BAD\u7EC3\u6B65\u9AA4\u7684\u6570\u91CF\u3002\u8BF7\u8BB0\u4F4F\uFF0C\u6211\u4EEC\u5E94\u8BE5\u59CB\u7EC8\u5728\u51C6\u5907\u597Ddataloader\u540E\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u56E0\u4E3A\u8BE5\u65B9\u6CD5\u4F1A\u6539\u53D8\u5176\u957F\u5EA6\u3002\u6211\u4EEC\u4F7F\u7528\u7ECF\u5178\u7EBF\u6027\u5B66\u4E60\u7387\u8C03\u5EA6\uFF1A"),ct=m(),q(ms.$$.fragment),Tt=m(),ls=_("p"),ce=n("\u6700\u540E\uFF0C\u8981\u5C06\u6211\u4EEC\u7684\u6A21\u578B\u63A8\u9001\u5230 Hub\uFF0C\u6211\u4EEC\u9700\u8981\u521B\u5EFA\u4E00\u4E2A "),Ie=_("code"),Ne=n("Repository"),ja=n(" \u5DE5\u4F5C\u6587\u4EF6\u5939\u4E2D\u7684\u5BF9\u8C61\u3002\u5982\u679C\u60A8\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55 Hugging Face\u3002\u6211\u4EEC\u5C06\u4ECE\u6211\u4EEC\u60F3\u8981\u4E3A\u6A21\u578B\u63D0\u4F9B\u7684\u6A21\u578B ID \u4E2D\u786E\u5B9A\u5B58\u50A8\u5E93\u540D\u79F0\uFF08\u60A8\u53EF\u4EE5\u81EA\u7531\u5730\u7528\u81EA\u5DF1\u7684\u9009\u62E9\u66FF\u6362 "),Se=_("code"),rs=n("repo_name"),wa=n(" \uFF1B\u5B83\u53EA\u9700\u8981\u5305\u542B\u60A8\u7684\u7528\u6237\u540D\uFF0C\u53EF\u4EE5\u4F7F\u7528"),ue=_("code"),ya=n("get_full_repo_name()"),va=n("\u51FD\u6570\u7684\u67E5\u770B\u76EE\u524D\u7684repo_name\uFF09\uFF1A"),me=m(),q(fe.$$.fragment),Dt=m(),q(zs.$$.fragment),Ct=m(),Re=_("p"),Ot=n("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5728\u672C\u5730\u6587\u4EF6\u5939\u4E2D\u514B\u9686\u8BE5\u5B58\u50A8\u5E93\u3002\u5982\u679C\u5B83\u5DF2\u7ECF\u5B58\u5728\uFF0C\u8FD9\u4E2A\u672C\u5730\u6587\u4EF6\u5939\u5E94\u8BE5\u662F\u6211\u4EEC\u6B63\u5728\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u7684\u514B\u9686\uFF1A"),ks=m(),q(fs.$$.fragment),qa=m(),js=_("p"),de=n("\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u4E0A\u4F20\u6211\u4EEC\u4FDD\u5B58\u7684\u4EFB\u4F55\u5185\u5BB9 "),At=_("code"),Gt=n("output_dir"),Be=n(" \u901A\u8FC7\u8C03\u7528 "),ut=_("code"),Mt=n("repo.push_to_hub()"),he=n(" \u65B9\u6CD5\u3002\u8FD9\u5C06\u5E2E\u52A9\u6211\u4EEC\u5728\u6BCF\u4E2A epoch \u7ED3\u675F\u65F6\u4E0A\u4F20\u4E2D\u95F4\u6A21\u578B\u3002\u5728\u6211\u4EEC\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u8BA9\u6211\u4EEC\u8FD0\u884C\u4E00\u4E2A\u5FEB\u901F\u6D4B\u8BD5\uFF0C\u770B\u770B\u8BC4\u4F30\u51FD\u6570\u662F\u5426\u6B63\u5E38\u5DE5\u4F5C\uFF1A"),mt=m(),q(ds.$$.fragment),ft=m(),q(os.$$.fragment),Ft=m(),ws=_("p"),Ea=n("\u8FD9\u4E9B\u635F\u5931\u548C\u56F0\u60D1\u5EA6\u7684\u503C\u975E\u5E38\u9AD8\uFF0C\u4F46\u8FD9\u5E76\u4E0D\u5947\u602A\uFF0C\u56E0\u4E3A\u6211\u4EEC\u8FD8\u6CA1\u6709\u8BAD\u7EC3\u8FC7\u6A21\u578B\u3002\u6709\u4E86\u8FD9\u4E2A\uFF0C\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u7F16\u5199\u8BAD\u7EC3\u811A\u672C\u7684\u6838\u5FC3\u90E8\u5206\uFF1A\u8BAD\u7EC3\u5FAA\u73AF\u3002\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\uFF0C\u6211\u4EEC\u904D\u5386\u6570\u636E\u52A0\u8F7D\u5668\u5E76\u5C06\u6279\u6B21\u4F20\u9012\u7ED9\u6A21\u578B\u3002\u6709\u4E86 logits\uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u8BC4\u4F30\u6211\u4EEC\u7684\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\u3002\u6211\u4EEC\u901A\u8FC7\u68AF\u5EA6\u7D2F\u79EF\u6B65\u9AA4\u7684\u6570\u91CF\u6765\u7F29\u653E\u635F\u5931\uFF0C\u4EE5\u4FBF\u5728\u805A\u5408\u66F4\u591A\u6B65\u9AA4\u65F6\u4E0D\u4F1A\u4EA7\u751F\u66F4\u5927\u7684\u635F\u5931\u3002\u5728\u6211\u4EEC\u4F18\u5316\u4E4B\u524D\uFF0C\u6211\u4EEC\u8FD8\u526A\u8F91\u4E86\u68AF\u5EA6\u4EE5\u83B7\u5F97\u66F4\u597D\u7684\u6536\u655B\u6027\u3002\u6700\u540E\uFF0C\u6BCF\u9694\u51E0\u6B65\uFF0C\u6211\u4EEC\u5C31\u4F1A\u4F7F\u7528\u65B0\u7684 "),dt=_("code"),Lt=n("evaluate()"),ps=n(" \u51FD\u6570\u8BC4\u4F30\u6A21\u578B\uFF1A"),Ht=m(),q(Ps.$$.fragment),It=m(),Ue=_("p"),We=n("\u5C31\u662F\u8FD9\u6837 - \u60A8\u73B0\u5728\u62E5\u6709\u81EA\u5DF1\u7684\u56E0\u679C\u8BED\u8A00\u6A21\u578B\uFF08\u4F8B\u5982 GPT-2\uFF09\u7684\u81EA\u5B9A\u4E49\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u60A8\u53EF\u4EE5\u6839\u636E\u81EA\u5DF1\u7684\u9700\u8981\u8FDB\u4E00\u6B65\u81EA\u5B9A\u4E49\u3002"),Nt=m(),q($e.$$.fragment),Xe=m(),q(be.$$.fragment),this.h()},l(a){l=c(a,"H2",{class:!0});var k=u(l);d=c(k,"A",{id:!0,class:!0,href:!0});var xa=u(d);p=c(xa,"SPAN",{});var Ke=u(p);E(h.$$.fragment,Ke),Ke.forEach(e),xa.forEach(e),y=f(k),j=c(k,"SPAN",{});var za=u(j);v=r(za,"\u7528 \u{1F917} Accelerate \u8BAD\u7EC3"),za.forEach(e),k.forEach(e),P=f(a),w=c(a,"P",{});var ge=u(w);D=r(ge,"\u6211\u4EEC\u5DF2\u7ECF\u770B\u5230\u4E86\u5982\u4F55\u4F7F\u7528 "),G=c(ge,"CODE",{});var Qa=u(G);L=r(Qa,"Trainer"),Qa.forEach(e),$=r(ge," \uFF0C\u8FD9\u53EF\u4EE5\u5141\u8BB8\u4E00\u4E9B\u81EA\u5B9A\u4E49\u3002\u7136\u800C\uFF0C\u6709\u65F6\u6211\u4EEC\u60F3\u8981\u5B8C\u5168\u63A7\u5236\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u6216\u8005\u6211\u4EEC\u60F3\u8981\u8FDB\u884C\u4E00\u4E9B\u5947\u7279\u7684\u66F4\u6539\u3002\u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B \u{1F917} Accelerate \u662F\u4E00\u4E2A\u4E0D\u9519\u7684\u9009\u62E9\uFF0C\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u9010\u6B65\u4ECB\u7ECD\u4F7F\u7528\u5B83\u6765\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u7684\u6B65\u9AA4\u3002\u4E3A\u4E86\u8BA9\u4E8B\u60C5\u53D8\u5F97\u66F4\u6709\u8DA3\uFF0C\u6211\u4EEC\u8FD8\u5C06\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\u6DFB\u52A0\u4E00\u4E9B\u4FEE\u6539\u3002"),ge.forEach(e),M=f(a),E(I.$$.fragment,a),R=f(a),A=c(a,"P",{});var X=u(A);B=r(X,"\u7531\u4E8E\u6211\u4EEC\u4E3B\u8981\u5BF9\u6570\u636E\u79D1\u5B66\u5E93\u7684\u5408\u7406\u81EA\u52A8\u586B\u5145\u611F\u5174\u8DA3\uFF0C\u56E0\u6B64\u5BF9\u66F4\u591A\u4F7F\u7528\u8FD9\u4E9B\u5E93\u7684\u8BAD\u7EC3\u6837\u672C\u7ED9\u4E88\u66F4\u591A\u6743\u91CD\u662F\u6709\u610F\u4E49\u7684\u3002\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u4F7F\u7528\u5173\u952E\u5B57\u8F7B\u677E\u8BC6\u522B\u8FD9\u4E9B\u793A\u4F8B\uFF0C\u4F8B\u5982 "),W=c(X,"CODE",{});var ht=u(W);F=r(ht,"plt"),ht.forEach(e),N=r(X,"\u3001"),S=c(X,"CODE",{});var sl=u(S);Y=r(sl,"pd"),sl.forEach(e),Z=r(X,"\u3001"),K=c(X,"CODE",{});var Pa=u(K);es=r(Pa,"sk"),Pa.forEach(e),is=r(X,"\u3001"),C=c(X,"CODE",{});var ke=u(C);U=r(ke,"fit"),ke.forEach(e),Pe=r(X,"\u548C"),qs=c(X,"CODE",{});var Ta=u(qs);hs=r(Ta,"predict"),Ta.forEach(e),Es=r(X,"\u7B49\u5173\u952E\u5B57\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5F88\u5BB9\u6613\u5730\u8BC6\u522B\u8FD9\u4E9B\u793A\u4F8B\uFF0C\u8FD9\u4E9B\u5173\u952E\u5B57\u662Fmatplotlib\u6700\u5E38\u7528\u7684\u5BFC\u5165\u540D\u79F0\u3002"),J=c(X,"CODE",{});var Ve=u(J);Te=r(Ve,"Pyplot"),Ve.forEach(e),De=r(X,", "),tt=c(X,"CODE",{});var el=u(tt);pa=r(el,"pandas"),el.forEach(e),at=r(X,"\u548C"),lt=c(X,"CODE",{});var Da=u(lt);ia=r(Da,"sklearn"),Da.forEach(e),bt=r(X,"\u4EE5\u53CA\u540E\u8005\u7684\u62DF\u5408/\u9884\u6D4B\u6A21\u5F0F\u3002\u5982\u679C\u8FD9\u4E9B\u90FD\u8868\u793A\u4E3A\u5355\u4E2A\u6807\u8BB0\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u68C0\u67E5\u5B83\u4EEC\u662F\u5426\u51FA\u73B0\u5728\u8F93\u5165\u5E8F\u5217\u4E2D\u3002\u6807\u8BB0\u53EF\u80FD\u6709\u4E00\u4E2A\u7A7A\u683C\u524D\u7F00\uFF0C\u56E0\u6B64\u6211\u4EEC\u8FD8\u5C06\u5728\u6807\u8BB0\u5668\u8BCD\u6C47\u8868\u4E2D\u68C0\u67E5\u8FD9\u4E9B\u7248\u672C\u3002\u4E3A\u4E86\u9A8C\u8BC1\u5B83\u662F\u5426\u6709\u6548\uFF0C\u6211\u4EEC\u5C06\u6DFB\u52A0\u4E00\u4E2A\u6D4B\u8BD5token \uFF0C\u8BE5token \u5E94\u62C6\u5206\u4E3A\u591A\u4E2Atokens\uFF1A"),X.forEach(e),ts=f(a),E(Ce.$$.fragment,a),nt=f(a),E(V.$$.fragment,a),_a=f(a),Qs=c(a,"P",{});var Ts=u(Qs);Gs=r(Ts,"\u592A\u597D\u4E86\uFF0C\u8FD9\u4F3C\u4E4E\u5F88\u597D\u7528\uFF01\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u7F16\u5199\u4E00\u4E2A\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\uFF0C\u5B83\u5C06\u8F93\u5165\u5E8F\u5217\u3001logits \u548C\u6211\u4EEC\u521A\u521A\u9009\u62E9\u7684\u5173\u200B\u200B\u952E\u6807\u8BB0\u4F5C\u4E3A\u8F93\u5165\u3002\u9996\u5148\uFF0C\u6211\u4EEC\u9700\u8981\u5BF9\u9F50 logits \u548C\u8F93\u5165\uFF1A\u5411\u53F3\u79FB\u52A8\u4E00\u4E2A\u7684\u8F93\u5165\u5E8F\u5217\u5F62\u6210\u6807\u7B7E\uFF0C\u56E0\u4E3A\u4E0B\u4E00\u4E2A\u6807\u8BB0\u662F\u5F53\u524D\u6807\u8BB0\u7684\u6807\u7B7E\u3002\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u4ECE\u8F93\u5165\u5E8F\u5217\u7684\u7B2C\u4E8C\u4E2A\u6807\u8BB0\u5F00\u59CB\u6807\u8BB0\u6765\u5B9E\u73B0\u8FD9\u4E00\u70B9\uFF0C\u56E0\u4E3A\u6A21\u578B\u65E0\u8BBA\u5982\u4F55\u90FD\u4E0D\u4F1A\u5BF9\u7B2C\u4E00\u4E2A\u6807\u8BB0\u8FDB\u884C\u9884\u6D4B\u3002\u7136\u540E\u6211\u4EEC\u5207\u65AD\u6700\u540E\u4E00\u4E2A logit\uFF0C\u56E0\u4E3A\u6211\u4EEC\u6CA1\u6709\u5B8C\u6574\u8F93\u5165\u5E8F\u5217\u4E4B\u540E\u7684\u6807\u8BB0\u7684\u6807\u7B7E\u3002\u6709\u4E86\u8FD9\u4E2A\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8BA1\u7B97\u6BCF\u4E2A\u6837\u672C\u7684\u635F\u5931\u5E76\u8BA1\u7B97\u6BCF\u4E2A\u6837\u672C\u4E2D\u6240\u6709\u5173\u952E\u5B57\u7684\u51FA\u73B0\u6B21\u6570\u3002\u6700\u540E\uFF0C\u6211\u4EEC\u4F7F\u7528\u51FA\u73B0\u6B21\u6570\u4F5C\u4E3A\u6743\u91CD\u8BA1\u7B97\u6240\u6709\u6837\u672C\u7684\u52A0\u6743\u5E73\u5747\u503C\u3002\u7531\u4E8E\u6211\u4EEC\u4E0D\u60F3\u6254\u6389\u6240\u6709\u6CA1\u6709\u5173\u952E\u5B57\u7684\u6837\u672C\uFF0C\u6211\u4EEC\u5C06\u6743\u91CD\u52A01\uFF1A"),Ts.forEach(e),gt=f(a),E(_s.$$.fragment,a),kt=f(a),Oe=c(a,"P",{});var tl=u(Oe);jt=r(tl,"\u5728\u6211\u4EEC\u5F00\u59CB\u4F7F\u7528\u8FD9\u4E2A\u5F88\u68D2\u7684\u65B0\u635F\u5931\u51FD\u6570\u8FDB\u884C\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u51C6\u5907\u4E00\u4E9B\u4E1C\u897F\uFF1A"),tl.forEach(e),Ms=f(a),$s=c(a,"UL",{});var Zs=u($s);Ae=c(Zs,"LI",{});var al=u(Ae);ns=r(al,"\u6211\u4EEC\u9700\u8981\u6570\u636E\u52A0\u8F7D\u5668\u6765\u6279\u91CF\u52A0\u8F7D\u6570\u636E\u3002"),al.forEach(e),ca=f(Zs),xs=c(Zs,"LI",{});var ll=u(xs);ua=r(ll,"\u6211\u4EEC\u9700\u8981\u8BBE\u7F6E\u6743\u91CD\u8870\u51CF\u53C2\u6570\u3002"),ll.forEach(e),ma=f(Zs),se=c(Zs,"LI",{});var Rt=u(se);fa=r(Rt,"\u6709\u65F6\u6211\u4EEC\u60F3\u8981\u6C42\u503C\uFF0C\u56E0\u6B64\u5C06\u6C42\u503C\u4EE3\u7801\u5305\u88C5\u5728\u4E00\u4E2A\u51FD\u6570\u4E2D\u662F\u6709\u610F\u4E49\u7684\u3002"),Rt.forEach(e),Zs.forEach(e),wt=f(a),as=c(a,"P",{});var Ye=u(as);da=r(Ye,"\u8BA9\u6211\u4EEC\u4ECE\u6570\u636E\u52A0\u8F7D\u5668\u5F00\u59CB\u3002\u6211\u4EEC\u53EA\u9700\u8981\u5C06\u6570\u636E\u96C6\u7684\u683C\u5F0F\u8BBE\u7F6E\u4E3A "),rt=c(Ye,"CODE",{});var nl=u(rt);yt=r(nl,'"torch"'),nl.forEach(e),Fs=r(Ye,"\uFF0C\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4F20\u9012\u7ED9 PyTorch "),ot=c(Ye,"CODE",{});var Ca=u(ot);pt=r(Ca,"DataLoader"),Ca.forEach(e),ha=r(Ye," ,\u540C\u65F6\u8BBE\u7F6E\u9002\u5F53\u7684\u6279\u91CF\u5927\u5C0F\uFF1A"),Ye.forEach(e),vt=f(a),E(Ls.$$.fragment,a),Hs=f(a),ee=c(a,"P",{});var ys=u(ee);Ge=r(ys,"\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u5BF9\u53C2\u6570\u8FDB\u884C\u5206\u7EC4\uFF0C\u4EE5\u4FBF\u4F18\u5316\u5668\u77E5\u9053\u54EA\u4E9B\u5C06\u83B7\u5F97\u989D\u5916\u7684\u6743\u91CD\u8870\u51CF\u3002\u901A\u5E38\uFF0C\u6240\u6709\u504F\u5DEE\u548C LayerNorm \u6743\u91CD\u9879\u90FD\u4E0D\u53D7\u6B64\u9650\u5236\uFF1B\u4EE5\u4E0B\u6211\u4EEC\u5982\u4F55\u505A\u5230\u8FD9\u4E00\u70B9\uFF1A"),ys.forEach(e),qt=f(a),E(Is.$$.fragment,a),Ns=f(a),te=c(a,"P",{});var vs=u(te);ae=r(vs,"\u7531\u4E8E\u6211\u4EEC\u5E0C\u671B\u5728\u8BAD\u7EC3\u671F\u95F4\u5B9A\u671F\u5728\u9A8C\u8BC1\u96C6\u4E0A\u8BC4\u4F30\u6A21\u578B\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E5F\u4E3A\u6B64\u7F16\u5199\u4E00\u4E2A\u51FD\u6570\u3002\u5B83\u53EA\u662F\u8FD0\u884C\u8BC4\u4F30\u6570\u636E\u52A0\u8F7D\u5668\u5E76\u6536\u96C6\u8DE8\u8FDB\u7A0B\u7684\u6240\u6709\u635F\u5931\uFF1A"),vs.forEach(e),it=f(a),E(bs.$$.fragment,a),Et=f(a),cs=c(a,"P",{});var Ds=u(cs);le=r(Ds,"\u901A\u8FC7 "),Me=c(Ds,"CODE",{});var Cs=u(Me);Fe=r(Cs,"evaluate()"),Cs.forEach(e),$a=r(Ds," \u51FD\u6570\u6211\u4EEC\u5B9A\u671F\u53EF\u4EE5\u83B7\u53D6\u635F\u5931\u503C\u548C"),ne=c(Ds,"A",{href:!0});var rl=u(ne);re=r(rl,"perplexity"),rl.forEach(e),xt=r(Ds,"\u3002\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u91CD\u65B0\u5B9A\u4E49\u6211\u4EEC\u7684\u6A21\u578B\u4EE5\u786E\u4FDD\u6211\u4EEC\u518D\u6B21\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\uFF1A"),Ds.forEach(e),Ss=f(a),E(Rs.$$.fragment,a),oe=f(a),Le=c(a,"P",{});var Bt=u(Le);zt=r(Bt,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5B9A\u4E49\u6211\u4EEC\u7684\u4F18\u5316\u5668\uFF0C\u4F7F\u7528\u4E4B\u524D\u7684\u51FD\u6570\u6765\u5206\u5272\u6743\u91CD\u8870\u51CF\u7684\u53C2\u6570\uFF1A"),Bt.forEach(e),Bs=f(a),E(Us.$$.fragment,a),Ws=f(a),pe=c(a,"P",{});var ol=u(pe);Xs=r(ol,"\u73B0\u5728\u8BA9\u6211\u4EEC\u51C6\u5907\u6A21\u578B\u3001\u4F18\u5316\u5668\u548C\u6570\u636E\u52A0\u8F7D\u5668\uFF0C\u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u5F00\u59CB\u8BAD\u7EC3\uFF1A"),ol.forEach(e),_t=f(a),E(gs.$$.fragment,a),Pt=f(a),E(Ks.$$.fragment,a),Vs=f(a),us=c(a,"P",{});var Ze=u(us);ie=r(Ze,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u53D1\u9001\u4E86\u6211\u4EEC\u7684 "),He=c(Ze,"CODE",{});var Ut=u(He);Ys=r(Ut,"train_dataloader"),Ut.forEach(e),ba=r(Ze,"\u5230 "),_e=c(Ze,"CODE",{});var pl=u(_e);ga=r(pl,"accelerator.prepare()"),pl.forEach(e),ka=r(Ze," \uFF0C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u5B83\u7684\u957F\u5EA6\u6765\u8BA1\u7B97\u8BAD\u7EC3\u6B65\u9AA4\u7684\u6570\u91CF\u3002\u8BF7\u8BB0\u4F4F\uFF0C\u6211\u4EEC\u5E94\u8BE5\u59CB\u7EC8\u5728\u51C6\u5907\u597Ddataloader\u540E\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u56E0\u4E3A\u8BE5\u65B9\u6CD5\u4F1A\u6539\u53D8\u5176\u957F\u5EA6\u3002\u6211\u4EEC\u4F7F\u7528\u7ECF\u5178\u7EBF\u6027\u5B66\u4E60\u7387\u8C03\u5EA6\uFF1A"),Ze.forEach(e),ct=f(a),E(ms.$$.fragment,a),Tt=f(a),ls=c(a,"P",{});var Js=u(ls);ce=r(Js,"\u6700\u540E\uFF0C\u8981\u5C06\u6211\u4EEC\u7684\u6A21\u578B\u63A8\u9001\u5230 Hub\uFF0C\u6211\u4EEC\u9700\u8981\u521B\u5EFA\u4E00\u4E2A "),Ie=c(Js,"CODE",{});var Oa=u(Ie);Ne=r(Oa,"Repository"),Oa.forEach(e),ja=r(Js," \u5DE5\u4F5C\u6587\u4EF6\u5939\u4E2D\u7684\u5BF9\u8C61\u3002\u5982\u679C\u60A8\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55 Hugging Face\u3002\u6211\u4EEC\u5C06\u4ECE\u6211\u4EEC\u60F3\u8981\u4E3A\u6A21\u578B\u63D0\u4F9B\u7684\u6A21\u578B ID \u4E2D\u786E\u5B9A\u5B58\u50A8\u5E93\u540D\u79F0\uFF08\u60A8\u53EF\u4EE5\u81EA\u7531\u5730\u7528\u81EA\u5DF1\u7684\u9009\u62E9\u66FF\u6362 "),Se=c(Js,"CODE",{});var Os=u(Se);rs=r(Os,"repo_name"),Os.forEach(e),wa=r(Js," \uFF1B\u5B83\u53EA\u9700\u8981\u5305\u542B\u60A8\u7684\u7528\u6237\u540D\uFF0C\u53EF\u4EE5\u4F7F\u7528"),ue=c(Js,"CODE",{});var il=u(ue);ya=r(il,"get_full_repo_name()"),il.forEach(e),va=r(Js,"\u51FD\u6570\u7684\u67E5\u770B\u76EE\u524D\u7684repo_name\uFF09\uFF1A"),Js.forEach(e),me=f(a),E(fe.$$.fragment,a),Dt=f(a),E(zs.$$.fragment,a),Ct=f(a),Re=c(a,"P",{});var Wt=u(Re);Ot=r(Wt,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u5728\u672C\u5730\u6587\u4EF6\u5939\u4E2D\u514B\u9686\u8BE5\u5B58\u50A8\u5E93\u3002\u5982\u679C\u5B83\u5DF2\u7ECF\u5B58\u5728\uFF0C\u8FD9\u4E2A\u672C\u5730\u6587\u4EF6\u5939\u5E94\u8BE5\u662F\u6211\u4EEC\u6B63\u5728\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u7684\u514B\u9686\uFF1A"),Wt.forEach(e),ks=f(a),E(fs.$$.fragment,a),qa=f(a),js=c(a,"P",{});var Je=u(js);de=r(Je,"\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u4E0A\u4F20\u6211\u4EEC\u4FDD\u5B58\u7684\u4EFB\u4F55\u5185\u5BB9 "),At=c(Je,"CODE",{});var _l=u(At);Gt=r(_l,"output_dir"),_l.forEach(e),Be=r(Je," \u901A\u8FC7\u8C03\u7528 "),ut=c(Je,"CODE",{});var Xt=u(ut);Mt=r(Xt,"repo.push_to_hub()"),Xt.forEach(e),he=r(Je," \u65B9\u6CD5\u3002\u8FD9\u5C06\u5E2E\u52A9\u6211\u4EEC\u5728\u6BCF\u4E2A epoch \u7ED3\u675F\u65F6\u4E0A\u4F20\u4E2D\u95F4\u6A21\u578B\u3002\u5728\u6211\u4EEC\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u8BA9\u6211\u4EEC\u8FD0\u884C\u4E00\u4E2A\u5FEB\u901F\u6D4B\u8BD5\uFF0C\u770B\u770B\u8BC4\u4F30\u51FD\u6570\u662F\u5426\u6B63\u5E38\u5DE5\u4F5C\uFF1A"),Je.forEach(e),mt=f(a),E(ds.$$.fragment,a),ft=f(a),E(os.$$.fragment,a),Ft=f(a),ws=c(a,"P",{});var Kt=u(ws);Ea=r(Kt,"\u8FD9\u4E9B\u635F\u5931\u548C\u56F0\u60D1\u5EA6\u7684\u503C\u975E\u5E38\u9AD8\uFF0C\u4F46\u8FD9\u5E76\u4E0D\u5947\u602A\uFF0C\u56E0\u4E3A\u6211\u4EEC\u8FD8\u6CA1\u6709\u8BAD\u7EC3\u8FC7\u6A21\u578B\u3002\u6709\u4E86\u8FD9\u4E2A\uFF0C\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u7F16\u5199\u8BAD\u7EC3\u811A\u672C\u7684\u6838\u5FC3\u90E8\u5206\uFF1A\u8BAD\u7EC3\u5FAA\u73AF\u3002\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\uFF0C\u6211\u4EEC\u904D\u5386\u6570\u636E\u52A0\u8F7D\u5668\u5E76\u5C06\u6279\u6B21\u4F20\u9012\u7ED9\u6A21\u578B\u3002\u6709\u4E86 logits\uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u8BC4\u4F30\u6211\u4EEC\u7684\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\u3002\u6211\u4EEC\u901A\u8FC7\u68AF\u5EA6\u7D2F\u79EF\u6B65\u9AA4\u7684\u6570\u91CF\u6765\u7F29\u653E\u635F\u5931\uFF0C\u4EE5\u4FBF\u5728\u805A\u5408\u66F4\u591A\u6B65\u9AA4\u65F6\u4E0D\u4F1A\u4EA7\u751F\u66F4\u5927\u7684\u635F\u5931\u3002\u5728\u6211\u4EEC\u4F18\u5316\u4E4B\u524D\uFF0C\u6211\u4EEC\u8FD8\u526A\u8F91\u4E86\u68AF\u5EA6\u4EE5\u83B7\u5F97\u66F4\u597D\u7684\u6536\u655B\u6027\u3002\u6700\u540E\uFF0C\u6BCF\u9694\u51E0\u6B65\uFF0C\u6211\u4EEC\u5C31\u4F1A\u4F7F\u7528\u65B0\u7684 "),dt=c(Kt,"CODE",{});var cl=u(dt);Lt=r(cl,"evaluate()"),cl.forEach(e),ps=r(Kt," \u51FD\u6570\u8BC4\u4F30\u6A21\u578B\uFF1A"),Kt.forEach(e),Ht=f(a),E(Ps.$$.fragment,a),It=f(a),Ue=c(a,"P",{});var Aa=u(Ue);We=r(Aa,"\u5C31\u662F\u8FD9\u6837 - \u60A8\u73B0\u5728\u62E5\u6709\u81EA\u5DF1\u7684\u56E0\u679C\u8BED\u8A00\u6A21\u578B\uFF08\u4F8B\u5982 GPT-2\uFF09\u7684\u81EA\u5B9A\u4E49\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u60A8\u53EF\u4EE5\u6839\u636E\u81EA\u5DF1\u7684\u9700\u8981\u8FDB\u4E00\u6B65\u81EA\u5B9A\u4E49\u3002"),Aa.forEach(e),Nt=f(a),E($e.$$.fragment,a),Xe=f(a),E(be.$$.fragment,a),this.h()},h(){H(d,"id","accelerate"),H(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"),H(d,"href","#accelerate"),H(l,"class","relative group"),H(ne,"href","/course/chapter7/3")},m(a,k){o(a,l,k),t(l,d),t(d,p),x(h,p,null),t(l,y),t(l,j),t(j,v),o(a,P,k),o(a,w,k),t(w,D),t(w,G),t(G,L),t(w,$),o(a,M,k),x(I,a,k),o(a,R,k),o(a,A,k),t(A,B),t(A,W),t(W,F),t(A,N),t(A,S),t(S,Y),t(A,Z),t(A,K),t(K,es),t(A,is),t(A,C),t(C,U),t(A,Pe),t(A,qs),t(qs,hs),t(A,Es),t(A,J),t(J,Te),t(A,De),t(A,tt),t(tt,pa),t(A,at),t(A,lt),t(lt,ia),t(A,bt),o(a,ts,k),x(Ce,a,k),o(a,nt,k),x(V,a,k),o(a,_a,k),o(a,Qs,k),t(Qs,Gs),o(a,gt,k),x(_s,a,k),o(a,kt,k),o(a,Oe,k),t(Oe,jt),o(a,Ms,k),o(a,$s,k),t($s,Ae),t(Ae,ns),t($s,ca),t($s,xs),t(xs,ua),t($s,ma),t($s,se),t(se,fa),o(a,wt,k),o(a,as,k),t(as,da),t(as,rt),t(rt,yt),t(as,Fs),t(as,ot),t(ot,pt),t(as,ha),o(a,vt,k),x(Ls,a,k),o(a,Hs,k),o(a,ee,k),t(ee,Ge),o(a,qt,k),x(Is,a,k),o(a,Ns,k),o(a,te,k),t(te,ae),o(a,it,k),x(bs,a,k),o(a,Et,k),o(a,cs,k),t(cs,le),t(cs,Me),t(Me,Fe),t(cs,$a),t(cs,ne),t(ne,re),t(cs,xt),o(a,Ss,k),x(Rs,a,k),o(a,oe,k),o(a,Le,k),t(Le,zt),o(a,Bs,k),x(Us,a,k),o(a,Ws,k),o(a,pe,k),t(pe,Xs),o(a,_t,k),x(gs,a,k),o(a,Pt,k),x(Ks,a,k),o(a,Vs,k),o(a,us,k),t(us,ie),t(us,He),t(He,Ys),t(us,ba),t(us,_e),t(_e,ga),t(us,ka),o(a,ct,k),x(ms,a,k),o(a,Tt,k),o(a,ls,k),t(ls,ce),t(ls,Ie),t(Ie,Ne),t(ls,ja),t(ls,Se),t(Se,rs),t(ls,wa),t(ls,ue),t(ue,ya),t(ls,va),o(a,me,k),x(fe,a,k),o(a,Dt,k),x(zs,a,k),o(a,Ct,k),o(a,Re,k),t(Re,Ot),o(a,ks,k),x(fs,a,k),o(a,qa,k),o(a,js,k),t(js,de),t(js,At),t(At,Gt),t(js,Be),t(js,ut),t(ut,Mt),t(js,he),o(a,mt,k),x(ds,a,k),o(a,ft,k),x(os,a,k),o(a,Ft,k),o(a,ws,k),t(ws,Ea),t(ws,dt),t(dt,Lt),t(ws,ps),o(a,Ht,k),x(Ps,a,k),o(a,It,k),o(a,Ue,k),t(Ue,We),o(a,Nt,k),x($e,a,k),o(a,Xe,k),x(be,a,k),St=!0},i(a){St||(b(h.$$.fragment,a),b(I.$$.fragment,a),b(Ce.$$.fragment,a),b(V.$$.fragment,a),b(_s.$$.fragment,a),b(Ls.$$.fragment,a),b(Is.$$.fragment,a),b(bs.$$.fragment,a),b(Rs.$$.fragment,a),b(Us.$$.fragment,a),b(gs.$$.fragment,a),b(Ks.$$.fragment,a),b(ms.$$.fragment,a),b(fe.$$.fragment,a),b(zs.$$.fragment,a),b(fs.$$.fragment,a),b(ds.$$.fragment,a),b(os.$$.fragment,a),b(Ps.$$.fragment,a),b($e.$$.fragment,a),b(be.$$.fragment,a),St=!0)},o(a){g(h.$$.fragment,a),g(I.$$.fragment,a),g(Ce.$$.fragment,a),g(V.$$.fragment,a),g(_s.$$.fragment,a),g(Ls.$$.fragment,a),g(Is.$$.fragment,a),g(bs.$$.fragment,a),g(Rs.$$.fragment,a),g(Us.$$.fragment,a),g(gs.$$.fragment,a),g(Ks.$$.fragment,a),g(ms.$$.fragment,a),g(fe.$$.fragment,a),g(zs.$$.fragment,a),g(fs.$$.fragment,a),g(ds.$$.fragment,a),g(os.$$.fragment,a),g(Ps.$$.fragment,a),g($e.$$.fragment,a),g(be.$$.fragment,a),St=!1},d(a){a&&e(l),z(h),a&&e(P),a&&e(w),a&&e(M),z(I,a),a&&e(R),a&&e(A),a&&e(ts),z(Ce,a),a&&e(nt),z(V,a),a&&e(_a),a&&e(Qs),a&&e(gt),z(_s,a),a&&e(kt),a&&e(Oe),a&&e(Ms),a&&e($s),a&&e(wt),a&&e(as),a&&e(vt),z(Ls,a),a&&e(Hs),a&&e(ee),a&&e(qt),z(Is,a),a&&e(Ns),a&&e(te),a&&e(it),z(bs,a),a&&e(Et),a&&e(cs),a&&e(Ss),z(Rs,a),a&&e(oe),a&&e(Le),a&&e(Bs),z(Us,a),a&&e(Ws),a&&e(pe),a&&e(_t),z(gs,a),a&&e(Pt),z(Ks,a),a&&e(Vs),a&&e(us),a&&e(ct),z(ms,a),a&&e(Tt),a&&e(ls),a&&e(me),z(fe,a),a&&e(Dt),z(zs,a),a&&e(Ct),a&&e(Re),a&&e(ks),z(fs,a),a&&e(qa),a&&e(js),a&&e(mt),z(ds,a),a&&e(ft),z(os,a),a&&e(Ft),a&&e(ws),a&&e(Ht),z(Ps,a),a&&e(It),a&&e(Ue),a&&e(Nt),z($e,a),a&&e(Xe),z(be,a)}}}function Do(O){let l,d,p,h,y;return{c(){l=_("p"),d=n("\u{1F6A8} \u5982\u679C\u60A8\u5728 TPU \u4E0A\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u5219\u9700\u8981\u5C06\u4ECE\u4E0A\u9762\u7684\u5355\u5143\u683C\u5F00\u59CB\u7684\u6240\u6709\u4EE3\u7801\u79FB\u52A8\u5230\u4E13\u7528\u7684\u8BAD\u7EC3\u51FD\u6570\u4E2D\u3002\u6709\u5173\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u53C2\u9605 "),p=_("a"),h=n("\u7B2C 3 \u7AE0"),y=n(" for more details."),this.h()},l(j){l=c(j,"P",{});var v=u(l);d=r(v,"\u{1F6A8} \u5982\u679C\u60A8\u5728 TPU \u4E0A\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u5219\u9700\u8981\u5C06\u4ECE\u4E0A\u9762\u7684\u5355\u5143\u683C\u5F00\u59CB\u7684\u6240\u6709\u4EE3\u7801\u79FB\u52A8\u5230\u4E13\u7528\u7684\u8BAD\u7EC3\u51FD\u6570\u4E2D\u3002\u6709\u5173\u8BE6\u7EC6\u4FE1\u606F\uFF0C\u8BF7\u53C2\u9605 "),p=c(v,"A",{href:!0});var P=u(p);h=r(P,"\u7B2C 3 \u7AE0"),P.forEach(e),y=r(v," for more details."),v.forEach(e),this.h()},h(){H(p,"href","/course/chapter3")},m(j,v){o(j,l,v),t(l,d),t(l,p),t(p,h),t(l,y)},d(j){j&&e(l)}}}function Co(O){let l,d,p,h,y;return{c(){l=_("p"),d=n("\u270F\uFE0F "),p=_("strong"),h=n("\u8BD5\u8BD5\u770B!"),y=n(" \u521B\u5EFA\u9002\u5408\u60A8\u7684\u7528\u4F8B\u7684\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\uFF0C\u6216\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\u6DFB\u52A0\u53E6\u4E00\u4E2A\u81EA\u5B9A\u4E49\u6B65\u9AA4\u3002")},l(j){l=c(j,"P",{});var v=u(l);d=r(v,"\u270F\uFE0F "),p=c(v,"STRONG",{});var P=u(p);h=r(P,"\u8BD5\u8BD5\u770B!"),P.forEach(e),y=r(v," \u521B\u5EFA\u9002\u5408\u60A8\u7684\u7528\u4F8B\u7684\u81EA\u5B9A\u4E49\u635F\u5931\u51FD\u6570\uFF0C\u6216\u5728\u8BAD\u7EC3\u5FAA\u73AF\u4E2D\u6DFB\u52A0\u53E6\u4E00\u4E2A\u81EA\u5B9A\u4E49\u6B65\u9AA4\u3002"),v.forEach(e)},m(j,v){o(j,l,v),t(l,d),t(l,p),t(p,h),t(l,y)},d(j){j&&e(l)}}}function Oo(O){let l,d,p,h,y;return{c(){l=_("p"),d=n("\u270F\uFE0F "),p=_("strong"),h=n("\u8BD5\u8BD5\u770B!"),y=n(" \u5728\u8FD0\u884C\u957F\u65F6\u95F4\u7684\u8BAD\u7EC3\u5B9E\u9A8C\u65F6\uFF0C\u6700\u597D\u4F7F\u7528 TensorBoard \u6216 Weights Biases \u7B49\u5DE5\u5177\u8BB0\u5F55\u91CD\u8981\u6307\u6807\u3002\u5411\u8BAD\u7EC3\u5FAA\u73AF\u6DFB\u52A0\u9002\u5F53\u7684\u65E5\u5FD7\u8BB0\u5F55\uFF0C\u4EE5\u4FBF\u60A8\u59CB\u7EC8\u53EF\u4EE5\u68C0\u67E5\u8BAD\u7EC3\u7684\u8FDB\u884C\u60C5\u51B5\u3002going.")},l(j){l=c(j,"P",{});var v=u(l);d=r(v,"\u270F\uFE0F "),p=c(v,"STRONG",{});var P=u(p);h=r(P,"\u8BD5\u8BD5\u770B!"),P.forEach(e),y=r(v," \u5728\u8FD0\u884C\u957F\u65F6\u95F4\u7684\u8BAD\u7EC3\u5B9E\u9A8C\u65F6\uFF0C\u6700\u597D\u4F7F\u7528 TensorBoard \u6216 Weights Biases \u7B49\u5DE5\u5177\u8BB0\u5F55\u91CD\u8981\u6307\u6807\u3002\u5411\u8BAD\u7EC3\u5FAA\u73AF\u6DFB\u52A0\u9002\u5F53\u7684\u65E5\u5FD7\u8BB0\u5F55\uFF0C\u4EE5\u4FBF\u60A8\u59CB\u7EC8\u53EF\u4EE5\u68C0\u67E5\u8BAD\u7EC3\u7684\u8FDB\u884C\u60C5\u51B5\u3002going."),v.forEach(e)},m(j,v){o(j,l,v),t(l,d),t(l,p),t(p,h),t(l,y)},d(j){j&&e(l)}}}function Ao(O){let l,d,p,h,y,j,v,P,w,D,G,L,$,M,I,R,A,B,W,F,N,S,Y,Z,K,es,is,C,U,Pe,qs,hs,Es,J,Te,De,tt,pa,at,lt,ia,bt,ts,Ce,nt,V,_a,Qs,Gs,gt,_s,kt,Oe,jt,Ms,$s,Ae,ns,ca,xs,ua,ma,se,fa,wt,as,da,rt,yt,Fs,ot,pt,ha,vt,Ls,Hs,ee,Ge,qt,Is,Ns,te,ae,it,bs,Et,cs,le,Me,Fe,$a,ne,re,xt,Ss,Rs,oe,Le,zt,Bs,Us,Ws,pe,Xs,_t,gs,Pt,Ks,Vs,us,ie,He,Ys,ba,_e,ga,ka,ct,ms,Tt,ls,ce,Ie,Ne,ja,Se,rs,wa,ue,ya,va,me,fe,Dt,zs,Ct,Re,Ot,ks,fs,qa,js,de,At,Gt,Be,ut,Mt,he,mt,ds,ft,os,Ft,ws,Ea,dt,Lt,ps,Ht,Ps,It,Ue,We,Nt,$e,Xe,be,St,a,k,xa,Ke,za,ge,Qa,X,ht,sl,Pa,ke,Ta,Ve,el,Da,Ts,tl,Zs,al,ll,Rt,Ye,nl,Ca,ys,vs,Ds,Cs,rl,Bt,ol,Ze,Ut,pl,Js,Oa,Os,il,Wt,Je,_l,Xt,Kt,cl,Aa,je,we,ul,ml,En,Bl,Ga,Ul,ye,ve,fl,dl,xn,Wl,hl,Vt,Xl,$l,zn,Kl,Ma,Vl,bl,Pn,Yl,gl,Tn,Zl,Fa,Jl,qe,Ee,kl,Yt,Ql,Zt,sn,La,Dn,en,Jt,Cn,Ol,On,An,tn,xe,ze,jl,wl,Gn,an,Ha,ln,Ia,nn,Qe,Mn,Al,Fn,Ln,Gl,Hn,In,rn,Na,on,Sa,pn,st,Nn,Ml,Sn,Rn,Fl,Bn,Un,_n,Ra,cn,Ba,un,Qt,Wn,Ll,Xn,Kn,mn,Ua,fn,Wa,dn,yl,vl,hn;p=new po({props:{fw:O[0]}});const Yn=[_o,io],Xa=[];function Zn(s,i){return s[0]==="pt"?0:1}P=Zn(O),w=Xa[P]=Yn[P](O),hs=new Vn({props:{id:"Vpjb1lu0MDk"}}),Hs=new T({props:{code:`def any_keyword_in_string(string, keywords):
    for keyword in keywords:
        if keyword in string:
            return True
    return False`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">any_keyword_in_string</span>(<span class="hljs-params">string, keywords</span>):
    <span class="hljs-keyword">for</span> keyword <span class="hljs-keyword">in</span> keywords:
        <span class="hljs-keyword">if</span> keyword <span class="hljs-keyword">in</span> string:
            <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span>
    <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span>`}}),Ns=new T({props:{code:`filters = ["pandas", "sklearn", "matplotlib", "seaborn"]
example_1 = "import numpy as np"
example_2 = "import pandas as pd"

print(
    any_keyword_in_string(example_1, filters), any_keyword_in_string(example_2, filters)
)`,highlighted:`filters = [<span class="hljs-string">&quot;pandas&quot;</span>, <span class="hljs-string">&quot;sklearn&quot;</span>, <span class="hljs-string">&quot;matplotlib&quot;</span>, <span class="hljs-string">&quot;seaborn&quot;</span>]
example_1 = <span class="hljs-string">&quot;import numpy as np&quot;</span>
example_2 = <span class="hljs-string">&quot;import pandas as pd&quot;</span>

<span class="hljs-built_in">print</span>(
    any_keyword_in_string(example_1, filters), any_keyword_in_string(example_2, filters)
)`}}),ae=new T({props:{code:"False True",highlighted:'<span class="hljs-literal">False</span> <span class="hljs-literal">True</span>'}}),le=new T({props:{code:`def filter_streaming_dataset(dataset, filters):
    filtered_dict = defaultdict(list)
    total = 0
    for sample in tqdm(iter(dataset)):
        total += 1
        if any_keyword_in_string(sample["content"], filters):
            for k, v in sample.items():
                filtered_dict[k].append(v)
    print(f"{len(filtered_dict['content'])/total:.2%} of data after filtering.")
    return Dataset.from_dict(filtered_dict)`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">filter_streaming_dataset</span>(<span class="hljs-params">dataset, filters</span>):
    filtered_dict = defaultdict(<span class="hljs-built_in">list</span>)
    total = <span class="hljs-number">0</span>
    <span class="hljs-keyword">for</span> sample <span class="hljs-keyword">in</span> tqdm(<span class="hljs-built_in">iter</span>(dataset)):
        total += <span class="hljs-number">1</span>
        <span class="hljs-keyword">if</span> any_keyword_in_string(sample[<span class="hljs-string">&quot;content&quot;</span>], filters):
            <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> sample.items():
                filtered_dict[k].append(v)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">{<span class="hljs-built_in">len</span>(filtered_dict[<span class="hljs-string">&#x27;content&#x27;</span>])/total:<span class="hljs-number">.2</span>%}</span> of data after filtering.&quot;</span>)
    <span class="hljs-keyword">return</span> Dataset.from_dict(filtered_dict)`}}),re=new T({props:{code:`# This cell will take a very long time to execute, so you should skip it and go to
# the next one!
from datasets import load_dataset

split = "train"  # "valid"
filters = ["pandas", "sklearn", "matplotlib", "seaborn"]

data = load_dataset(f"transformersbook/codeparrot-{split}", split=split, streaming=True)
filtered_data = filter_streaming_dataset(data, filters)`,highlighted:`<span class="hljs-comment"># This cell will take a very long time to execute, so you should skip it and go to</span>
<span class="hljs-comment"># the next one!</span>
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

split = <span class="hljs-string">&quot;train&quot;</span>  <span class="hljs-comment"># &quot;valid&quot;</span>
filters = [<span class="hljs-string">&quot;pandas&quot;</span>, <span class="hljs-string">&quot;sklearn&quot;</span>, <span class="hljs-string">&quot;matplotlib&quot;</span>, <span class="hljs-string">&quot;seaborn&quot;</span>]

data = load_dataset(<span class="hljs-string">f&quot;transformersbook/codeparrot-<span class="hljs-subst">{split}</span>&quot;</span>, split=split, streaming=<span class="hljs-literal">True</span>)
filtered_data = filter_streaming_dataset(data, filters)`}}),Ss=new T({props:{code:"3.26% of data after filtering.",highlighted:'<span class="hljs-number">3.26</span>% of data after filtering.'}}),Bs=new T({props:{code:`from datasets import load_dataset, DatasetDict

ds_train = load_dataset("huggingface-course/codeparrot-ds-train", split="train")
ds_valid = load_dataset("huggingface-course/codeparrot-ds-valid", split="train")

raw_datasets = DatasetDict(
    {
        "train": ds_train,  # .shuffle().select(range(50000)),
        "valid": ds_valid,  # .shuffle().select(range(500))
    }
)

raw_datasets`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, DatasetDict

ds_train = load_dataset(<span class="hljs-string">&quot;huggingface-course/codeparrot-ds-train&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
ds_valid = load_dataset(<span class="hljs-string">&quot;huggingface-course/codeparrot-ds-valid&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)

raw_datasets = DatasetDict(
    {
        <span class="hljs-string">&quot;train&quot;</span>: ds_train,  <span class="hljs-comment"># .shuffle().select(range(50000)),</span>
        <span class="hljs-string">&quot;valid&quot;</span>: ds_valid,  <span class="hljs-comment"># .shuffle().select(range(500))</span>
    }
)

raw_datasets`}}),Ws=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['repo_name', 'path', 'copies', 'size', 'content', 'license'],
        num_rows: 606720
    })
    valid: Dataset({
        features: ['repo_name', 'path', 'copies', 'size', 'content', 'license'],
        num_rows: 3322
    })
})`,highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;repo_name&#x27;</span>, <span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;copies&#x27;</span>, <span class="hljs-string">&#x27;size&#x27;</span>, <span class="hljs-string">&#x27;content&#x27;</span>, <span class="hljs-string">&#x27;license&#x27;</span>],
        num_rows: <span class="hljs-number">606720</span>
    })
    valid: Dataset({
        features: [<span class="hljs-string">&#x27;repo_name&#x27;</span>, <span class="hljs-string">&#x27;path&#x27;</span>, <span class="hljs-string">&#x27;copies&#x27;</span>, <span class="hljs-string">&#x27;size&#x27;</span>, <span class="hljs-string">&#x27;content&#x27;</span>, <span class="hljs-string">&#x27;license&#x27;</span>],
        num_rows: <span class="hljs-number">3322</span>
    })
})`}}),Xs=new oa({props:{$$slots:{default:[co]},$$scope:{ctx:O}}}),Vs=new T({props:{code:`for key in raw_datasets["train"][0]:
    print(f"{key.upper()}: {raw_datasets['train'][0][key][:200]}")`,highlighted:`<span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">{key.upper()}</span>: <span class="hljs-subst">{raw_datasets[<span class="hljs-string">&#x27;train&#x27;</span>][<span class="hljs-number">0</span>][key][:<span class="hljs-number">200</span>]}</span>&quot;</span>)`}}),ie=new T({props:{code:`'REPO_NAME: kmike/scikit-learn'
'PATH: sklearn/utils/__init__.py'
'COPIES: 3'
'SIZE: 10094'
'''CONTENT: """
The :mod:\`sklearn.utils\` module includes various utilites.
"""

from collections import Sequence

import numpy as np
from scipy.sparse import issparse
import warnings

from .murmurhash import murm
LICENSE: bsd-3-clause'''`,highlighted:`<span class="hljs-string">&#x27;REPO_NAME: kmike/scikit-learn&#x27;</span>
<span class="hljs-string">&#x27;PATH: sklearn/utils/__init__.py&#x27;</span>
<span class="hljs-string">&#x27;COPIES: 3&#x27;</span>
<span class="hljs-string">&#x27;SIZE: 10094&#x27;</span>
<span class="hljs-string">&#x27;&#x27;&#x27;CONTENT: &quot;&quot;&quot;
The :mod:\`sklearn.utils\` module includes various utilites.
&quot;&quot;&quot;

from collections import Sequence

import numpy as np
from scipy.sparse import issparse
import warnings

from .murmurhash import murm
LICENSE: bsd-3-clause&#x27;&#x27;&#x27;</span>`}}),ce=new Vn({props:{id:"ma1TrR7gE7I"}}),he=new T({props:{code:`from transformers import AutoTokenizer

context_length = 128
tokenizer = AutoTokenizer.from_pretrained("huggingface-course/code-search-net-tokenizer")

outputs = tokenizer(
    raw_datasets["train"][:2]["content"],
    truncation=True,
    max_length=context_length,
    return_overflowing_tokens=True,
    return_length=True,
)

print(f"Input IDs length: {len(outputs['input_ids'])}")
print(f"Input chunk lengths: {(outputs['length'])}")
print(f"Chunk mapping: {outputs['overflow_to_sample_mapping']}")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

context_length = <span class="hljs-number">128</span>
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;huggingface-course/code-search-net-tokenizer&quot;</span>)

outputs = tokenizer(
    raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][:<span class="hljs-number">2</span>][<span class="hljs-string">&quot;content&quot;</span>],
    truncation=<span class="hljs-literal">True</span>,
    max_length=context_length,
    return_overflowing_tokens=<span class="hljs-literal">True</span>,
    return_length=<span class="hljs-literal">True</span>,
)

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Input IDs length: <span class="hljs-subst">{<span class="hljs-built_in">len</span>(outputs[<span class="hljs-string">&#x27;input_ids&#x27;</span>])}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Input chunk lengths: <span class="hljs-subst">{(outputs[<span class="hljs-string">&#x27;length&#x27;</span>])}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Chunk mapping: <span class="hljs-subst">{outputs[<span class="hljs-string">&#x27;overflow_to_sample_mapping&#x27;</span>]}</span>&quot;</span>)`}}),ds=new T({props:{code:`Input IDs length: 34
Input chunk lengths: [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 117, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 41]
Chunk mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]`,highlighted:`Input IDs length: <span class="hljs-number">34</span>
Input chunk lengths: [<span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">117</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">128</span>, <span class="hljs-number">41</span>]
Chunk mapping: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]`}}),k=new T({props:{code:`def tokenize(element):
    outputs = tokenizer(
        element["content"],
        truncation=True,
        max_length=context_length,
        return_overflowing_tokens=True,
        return_length=True,
    )
    input_batch = []
    for length, input_ids in zip(outputs["length"], outputs["input_ids"]):
        if length == context_length:
            input_batch.append(input_ids)
    return {"input_ids": input_batch}


tokenized_datasets = raw_datasets.map(
    tokenize, batched=True, remove_columns=raw_datasets["train"].column_names
)
tokenized_datasets`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize</span>(<span class="hljs-params">element</span>):
    outputs = tokenizer(
        element[<span class="hljs-string">&quot;content&quot;</span>],
        truncation=<span class="hljs-literal">True</span>,
        max_length=context_length,
        return_overflowing_tokens=<span class="hljs-literal">True</span>,
        return_length=<span class="hljs-literal">True</span>,
    )
    input_batch = []
    <span class="hljs-keyword">for</span> length, input_ids <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(outputs[<span class="hljs-string">&quot;length&quot;</span>], outputs[<span class="hljs-string">&quot;input_ids&quot;</span>]):
        <span class="hljs-keyword">if</span> length == context_length:
            input_batch.append(input_ids)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;input_ids&quot;</span>: input_batch}


tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(
    tokenize, batched=<span class="hljs-literal">True</span>, remove_columns=raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names
)
tokenized_datasets`}}),Ke=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['input_ids'],
        num_rows: 16702061
    })
    valid: Dataset({
        features: ['input_ids'],
        num_rows: 93164
    })
})`,highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;input_ids&#x27;</span>],
        num_rows: <span class="hljs-number">16702061</span>
    })
    valid: Dataset({
        features: [<span class="hljs-string">&#x27;input_ids&#x27;</span>],
        num_rows: <span class="hljs-number">93164</span>
    })
})`}}),ke=new oa({props:{$$slots:{default:[uo]},$$scope:{ctx:O}}});const Jn=[fo,mo],Ka=[];function Qn(s,i){return s[0]==="pt"?0:1}ys=Qn(O),vs=Ka[ys]=Jn[ys](O);const sr=[$o,ho],Va=[];function er(s,i){return s[0]==="pt"?0:1}je=er(O),we=Va[je]=sr[je](O),Ga=new T({props:{code:`out = data_collator([tokenized_dataset["train"][i] for i in range(5)])
for key in out:
    print(f"{key} shape: {out[key].shape}")`,highlighted:`out = data_collator([tokenized_dataset[<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">5</span>)])
<span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> out:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">{key}</span> shape: <span class="hljs-subst">{out[key].shape}</span>&quot;</span>)`}});const tr=[go,bo],Ya=[];function ar(s,i){return s[0]==="pt"?0:1}ye=ar(O),ve=Ya[ye]=tr[ye](O);let Q=O[0]==="tf"&&Qr();Vt=new oa({props:{warning:!0,$$slots:{default:[ko]},$$scope:{ctx:O}}}),Ma=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()`}}),Fa=new T({props:{code:"huggingface-cli login",highlighted:"huggingface-cli login"}});const lr=[wo,jo],Za=[];function nr(s,i){return s[0]==="pt"?0:1}qe=nr(O),Ee=Za[qe]=lr[qe](O),Yt=new oa({props:{$$slots:{default:[yo]},$$scope:{ctx:O}}}),Zt=new oa({props:{$$slots:{default:[Eo]},$$scope:{ctx:O}}});const rr=[zo,xo],Ja=[];function or(s,i){return s[0]==="pt"?0:1}xe=or(O),ze=Ja[xe]=rr[xe](O),Ha=new T({props:{code:`txt = """\\
# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create scatter plot with x, y
"""
print(pipe(txt, num_return_sequences=1)[0]["generated_text"])`,highlighted:`txt = <span class="hljs-string">&quot;&quot;&quot;\\
# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create scatter plot with x, y
&quot;&quot;&quot;</span>
<span class="hljs-built_in">print</span>(pipe(txt, num_return_sequences=<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>])`}}),Ia=new T({props:{code:`# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create scatter plot with x, y
plt.scatter(x, y)

# create scatter`,highlighted:`<span class="hljs-comment"># create some data</span>
x = np.random.randn(<span class="hljs-number">100</span>)
y = np.random.randn(<span class="hljs-number">100</span>)

<span class="hljs-comment"># create scatter plot with x, y</span>
plt.scatter(x, y)

<span class="hljs-comment"># create scatter</span>`}}),Na=new T({props:{code:`txt = """\\
# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create dataframe from x and y
"""
print(pipe(txt, num_return_sequences=1)[0]["generated_text"])`,highlighted:`txt = <span class="hljs-string">&quot;&quot;&quot;\\
# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create dataframe from x and y
&quot;&quot;&quot;</span>
<span class="hljs-built_in">print</span>(pipe(txt, num_return_sequences=<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>])`}}),Sa=new T({props:{code:`# create some data
x = np.random.randn(100)
y = np.random.randn(100)

# create dataframe from x and y
df = pd.DataFrame({'x': x, 'y': y})
df.insert(0,'x', x)
for`,highlighted:`<span class="hljs-comment"># create some data</span>
x = np.random.randn(<span class="hljs-number">100</span>)
y = np.random.randn(<span class="hljs-number">100</span>)

<span class="hljs-comment"># create dataframe from x and y</span>
df = pd.DataFrame({<span class="hljs-string">&#x27;x&#x27;</span>: x, <span class="hljs-string">&#x27;y&#x27;</span>: y})
df.insert(<span class="hljs-number">0</span>,<span class="hljs-string">&#x27;x&#x27;</span>, x)
<span class="hljs-keyword">for</span>`}}),Ra=new T({props:{code:`txt = """\\
# dataframe with profession, income and name
df = pd.DataFrame({'profession': x, 'income':y, 'name': z})

# calculate the mean income per profession
"""
print(pipe(txt, num_return_sequences=1)[0]["generated_text"])`,highlighted:`txt = <span class="hljs-string">&quot;&quot;&quot;\\
# dataframe with profession, income and name
df = pd.DataFrame({&#x27;profession&#x27;: x, &#x27;income&#x27;:y, &#x27;name&#x27;: z})

# calculate the mean income per profession
&quot;&quot;&quot;</span>
<span class="hljs-built_in">print</span>(pipe(txt, num_return_sequences=<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>])`}}),Ba=new T({props:{code:`# dataframe with profession, income and name
df = pd.DataFrame({'profession': x, 'income':y, 'name': z})

# calculate the mean income per profession
profession = df.groupby(['profession']).mean()

# compute the`,highlighted:`<span class="hljs-comment"># dataframe with profession, income and name</span>
df = pd.DataFrame({<span class="hljs-string">&#x27;profession&#x27;</span>: x, <span class="hljs-string">&#x27;income&#x27;</span>:y, <span class="hljs-string">&#x27;name&#x27;</span>: z})

<span class="hljs-comment"># calculate the mean income per profession</span>
profession = df.groupby([<span class="hljs-string">&#x27;profession&#x27;</span>]).mean()

<span class="hljs-comment"># compute the</span>`}}),Ua=new T({props:{code:`txt = """
# import random forest regressor from scikit-learn
from sklearn.ensemble import RandomForestRegressor

# fit random forest model with 300 estimators on X, y:
"""
print(pipe(txt, num_return_sequences=1)[0]["generated_text"])`,highlighted:`txt = <span class="hljs-string">&quot;&quot;&quot;
# import random forest regressor from scikit-learn
from sklearn.ensemble import RandomForestRegressor

# fit random forest model with 300 estimators on X, y:
&quot;&quot;&quot;</span>
<span class="hljs-built_in">print</span>(pipe(txt, num_return_sequences=<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>])`}}),Wa=new T({props:{code:`# import random forest regressor from scikit-learn
from sklearn.ensemble import RandomForestRegressor

# fit random forest model with 300 estimators on X, y:
rf = RandomForestRegressor(n_estimators=300, random_state=random_state, max_depth=3)
rf.fit(X, y)
rf`,highlighted:`<span class="hljs-comment"># import random forest regressor from scikit-learn</span>
<span class="hljs-keyword">from</span> sklearn.ensemble <span class="hljs-keyword">import</span> RandomForestRegressor

<span class="hljs-comment"># fit random forest model with 300 estimators on X, y:</span>
rf = RandomForestRegressor(n_estimators=<span class="hljs-number">300</span>, random_state=random_state, max_depth=<span class="hljs-number">3</span>)
rf.fit(X, y)
rf`}});function pr(s,i){return s[0]==="tf"?To:Po}let $n=pr(O),$t=$n(O),ss=O[0]==="pt"&&so(O);return{c(){l=_("meta"),d=m(),q(p.$$.fragment),h=m(),y=_("h1"),j=n("\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u56E0\u679C\u8BED\u8A00\u6A21\u578B"),v=m(),w.c(),D=m(),G=_("p"),L=n("\u5230\u76EE\u524D\u4E3A\u6B62\uFF0C\u6211\u4EEC\u4E3B\u8981\u4F7F\u7528\u9884\u8BAD\u7EC3\u6A21\u578B\uFF0C\u5E76\u901A\u8FC7\u91CD\u7528\u9884\u8BAD\u7EC3\u7684\u6743\u91CD\u6765\u9488\u5BF9\u65B0\u7528\u4F8B\u5BF9\u5B83\u4EEC\u8FDB\u884C\u5FAE\u8C03\u3002\u6B63\u5982\u6211\u4EEC\u5728"),$=_("a"),M=n("\u7B2C\u4E00\u7AE0"),I=n(", \u8FD9\u901A\u5E38\u79F0\u4E3A\u8FC1\u79FB\u5B66\u4E60\uFF0C\u8FD9\u662F\u5C06 Transformer \u6A21\u578B\u5E94\u7528\u4E8E\u5927\u591A\u6570\u6807\u8BB0\u6570\u636E\u7A00\u758F\u7684\u73B0\u5B9E\u4E16\u754C\u7528\u4F8B\u7684\u975E\u5E38\u6210\u529F\u7684\u7B56\u7565\u3002\u5728\u672C\u7AE0\u4E2D\uFF0C\u6211\u4EEC\u5C06\u91C7\u7528\u4E0D\u540C\u7684\u65B9\u6CD5\u5E76\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u4E00\u4E2A\u5168\u65B0\u7684\u6A21\u578B\u3002\u5982\u679C\u60A8\u6709\u5927\u91CF\u6570\u636E\u5E76\u4E14\u5B83\u4E0E\u7528\u4E8E\u53EF\u7528\u6A21\u578B\u7684\u9884\u8BAD\u7EC3\u6570\u636E\u6709\u5F88\u5927\u4E0D\u540C\uFF0C\u90A3\u4E48\u8FD9\u662F\u4E00\u4E2A\u5F88\u597D\u7684\u65B9\u6CD5\u3002\u7136\u800C\uFF0C\u5B83\u4E5F\u9700\u8981\u66F4\u591A\u7684\u8BA1\u7B97\u8D44\u6E90\u6765\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\uFF0C\u800C\u4E0D\u4EC5\u4EC5\u662F\u5FAE\u8C03\u73B0\u6709\u7684\u6A21\u578B\u3002\u8BAD\u7EC3\u65B0\u6A21\u578B\u6709\u610F\u4E49\u7684\u793A\u4F8B\u5305\u62EC\u7531\u97F3\u7B26\u3001\u5206\u5B50\u5E8F\u5217\uFF08\u5982 DNA\uFF09\u6216\u7F16\u7A0B\u8BED\u8A00\u7EC4\u6210\u7684\u6570\u636E\u96C6\u3002\u540E\u8005\u6700\u8FD1\u53D7\u5230\u5173\u6CE8\uFF0C\u8FD9\u8981\u5F52\u529F\u4E8E TabNine \u548C GitHub \u7684 Copilot \u7B49\u5DE5\u5177\uFF0C\u5B83\u4EEC\u7531 OpenAI \u7684 Codex \u6A21\u578B\u63D0\u4F9B\u652F\u6301\uFF0C\u53EF\u4EE5\u751F\u6210\u957F\u4EE3\u7801\u5E8F\u5217\u3002\u8FD9\u79CD\u6587\u672C\u751F\u6210\u4EFB\u52A1\u6700\u597D\u4F7F\u7528\u81EA\u56DE\u5F52\u6216\u56E0\u679C\u8BED\u8A00\u6A21\u578B\uFF08\u4F8B\u5982 GPT-2\uFF09\u6765\u89E3\u51B3\u3002"),R=m(),A=_("p"),B=n("\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u6784\u5EFA\u4EE3\u7801\u751F\u6210\u6A21\u578B\u7684\u7F29\u5C0F\u7248\u672C\uFF1A\u6211\u4EEC\u5C06\u4F7F\u7528 Python \u4EE3\u7801\u7684\u5B50\u96C6\u4E13\u6CE8\u4E8E\u5355\u884C\u5B8C\u6210\u800C\u4E0D\u662F\u5B8C\u6574\u7684\u51FD\u6570\u6216\u7C7B\u3002\u5728 Python \u4E2D\u5904\u7406\u6570\u636E\u65F6\uFF0C\u60A8\u4F1A\u7ECF\u5E38\u63A5\u89E6 Python \u6570\u636E\u79D1\u5B66\u5806\u6808\uFF0C\u5305\u62EC "),W=_("code"),F=n("matplotlib"),N=n(" , "),S=_("code"),Y=n("seaborn"),Z=n(" , "),K=_("code"),es=n("pandas"),is=n(" \uFF0C \u548C "),C=_("code"),U=n("scikit-learn"),Pe=n(" \u5E93\u3002\u5728\u4F7F\u7528\u8FD9\u4E9B\u6846\u67B6\u65F6\uFF0C\u901A\u5E38\u9700\u8981\u67E5\u627E\u7279\u5B9A\u7684\u547D\u4EE4\uFF0C\u56E0\u6B64\u5982\u679C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u6765\u4E3A\u6211\u4EEC\u5B8C\u6210\u8FD9\u4E9B\u8C03\u7528\uFF0C\u90A3\u5C31\u592A\u597D\u4E86\u3002"),qs=m(),q(hs.$$.fragment),Es=m(),J=_("p"),Te=n("\u5728"),De=_("a"),tt=n("\u7B2C\u516D\u7AE0"),pa=n(" \u6211\u4EEC\u521B\u5EFA\u4E86\u4E00\u4E2A\u9AD8\u6548\u7684\u5206\u8BCD\u5668\u6765\u5904\u7406 Python \u6E90\u4EE3\u7801\uFF0C\u4F46\u6211\u4EEC\u4ECD\u7136\u9700\u8981\u4E00\u4E2A\u5927\u89C4\u6A21\u6570\u636E\u96C6\u6765\u9884\u8BAD\u7EC3\u6A21\u578B\u3002\u5728\u8FD9\u91CC\uFF0C\u6211\u4EEC\u5C06\u6211\u4EEC\u7684\u5206\u8BCD\u5668\u5E94\u7528\u5230\u6E90\u81EA GitHub \u5B58\u50A8\u5E93\u7684 Python \u4EE3\u7801\u8BED\u6599\u5E93\u3002\u7136\u540E\u6211\u4EEC\u5C06\u4F7F\u7528 "),at=_("code"),lt=n("Trainer"),ia=n(" API \u548C \u{1F917} Accelerate \u6765\u8BAD\u7EC3\u6A21\u578B\u3002\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427\uFF01"),bt=m(),ts=_("iframe"),nt=m(),V=_("iframe"),Qs=m(),Gs=_("p"),gt=n("\u8FD9\u5B9E\u9645\u4E0A\u5C55\u793A\u4E86\u4F7F\u7528\u672C\u8282\u4E2D\u8BAD\u7EC3\u5E76\u4E0A\u4F20\u5230 Hub \u7684\u6A21\u578B\u3002\u4F60\u53EF\u4EE5\u5728"),_s=_("a"),kt=n("\u8FD9\u91CC"),Oe=n("\u627E\u5230\u3002\u8BF7\u6CE8\u610F\uFF0C\u7531\u4E8E\u5728\u6587\u672C\u751F\u6210\u8FC7\u7A0B\u4E2D\u53D1\u751F\u4E86\u4E00\u4E9B\u968F\u673A\u5316\uFF0C\u60A8\u53EF\u80FD\u4F1A\u5F97\u5230\u7565\u6709\u4E0D\u540C\u7684\u7ED3\u679C\u3002"),jt=m(),Ms=_("h2"),$s=n("\u6536\u96C6\u6570\u636E"),Ae=m(),ns=_("p"),ca=n("Python \u4EE3\u7801\u53EF\u4EE5\u4ECE GitHub \u7B49\u4EE3\u7801\u5B58\u50A8\u5E93\u4E2D\u83B7\u5F97\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u6293\u53D6\u6BCF\u4E2A Python \u5B58\u50A8\u5E93\u6765\u4F7F\u7528\u5B83\u4EEC\u6765\u521B\u5EFA\u6570\u636E\u96C6\u3002\u8FD9\u662F\u5728"),xs=_("a"),ua=n("Transformers textbook"),ma=n("\u9884\u8BAD\u7EC3\u5927\u578B\u7684GPT-2 \u6A21\u578B\u3002\u4F7F\u7528\u5927\u7EA6 180 GB \u7684 GitHub \u8F6C\u50A8\uFF0C\u5176\u4E2D\u5305\u542B\u5927\u7EA6 2000 \u4E07\u4E2A Python \u6587\u4EF6\uFF0C\u79F0\u4E3A "),se=_("code"),fa=n("codeparrot"),wt=n(" \uFF0C\u4F5C\u8005\u6784\u5EFA\u4E86\u4E00\u4E2A\u6570\u636E\u96C6\uFF0C\u7136\u540E\u5728"),as=_("a"),da=n("Hugging Face Hub"),rt=n("\u4E0A\u5206\u4EAB\u51FA\u6765\u4E86."),yt=m(),Fs=_("p"),ot=n("\u7136\u800C\uFF0C\u5BF9\u5B8C\u6574\u8BED\u6599\u5E93\u7684\u8BAD\u7EC3\u65E2\u8017\u65F6\u53C8\u8D39\u529B\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u4E0E Python \u6570\u636E\u79D1\u5B66\u5806\u6808\u76F8\u5173\u7684\u6570\u636E\u96C6\u5B50\u96C6\u3002\u6240\u4EE5\uFF0C\u8BA9\u6211\u4EEC\u5F00\u59CB\u8FC7\u6EE4 "),pt=_("code"),ha=n("codeparrot"),vt=n(" \u5305\u542B\u6B64\u5806\u6808\u4E2D\u4EFB\u4F55\u5E93\u7684\u6240\u6709\u6587\u4EF6\u7684\u6570\u636E\u96C6\u3002\u7531\u4E8E\u6570\u636E\u96C6\u7684\u592A\u5927\uFF0C\u6211\u4EEC\u5E0C\u671B\u907F\u514D\u4E0B\u8F7D\u5B83\uFF1B\u56E0\u6B64\u53CD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u6D41\u529F\u80FD\u6765\u52A8\u6001\u8FC7\u6EE4\u5B83\u3002\u4E3A\u4E86\u4F7F\u7528\u524D\u9762\u63D0\u5230\u7684\u5E93\u8FC7\u6EE4\u4EE3\u7801\u793A\u4F8B\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u4EE5\u4E0B\u51FD\u6570\uFF1A"),Ls=m(),q(Hs.$$.fragment),ee=m(),Ge=_("p"),qt=n("\u8BA9\u6211\u4EEC\u7528\u4E24\u4E2A\u4F8B\u5B50\u6765\u6D4B\u8BD5\u4E00\u4E0B\uFF1A"),Is=m(),q(Ns.$$.fragment),te=m(),q(ae.$$.fragment),it=m(),bs=_("p"),Et=n("\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u5B83\u6765\u521B\u5EFA\u4E00\u4E2A\u51FD\u6570\u6765\u6D41\u5F0F\u4F20\u8F93\u6570\u636E\u96C6\u5E76\u8FC7\u6EE4\u6211\u4EEC\u60F3\u8981\u7684\u5143\u7D20\uFF1A"),cs=m(),q(le.$$.fragment),Me=m(),Fe=_("p"),$a=n("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7B80\u5355\u5730\u5C06\u6B64\u51FD\u6570\u5E94\u7528\u4E8E\u6D41\u6570\u636E\u96C6\uFF1A"),ne=m(),q(re.$$.fragment),xt=m(),q(Ss.$$.fragment),Rs=m(),oe=_("p"),Le=n("\u8FD9\u7ED9\u6211\u4EEC\u7559\u4E0B\u4E86\u5927\u7EA6 3% \u7684\u539F\u59CB\u6570\u636E\u96C6\uFF0C\u8FD9\u4E2A\u6570\u636E\u96C6\u4ECD\u7136\u76F8\u5F53\u53EF\u89C2\u2014\u2014\u7ED3\u679C\u6570\u636E\u96C6\u6709 6 GB\uFF0C\u5305\u542B 600,000 \u4E2A Python \u811A\u672C\uFF01\u8FC7\u6EE4\u5B8C\u6574\u6570\u636E\u96C6\u53EF\u80FD\u9700\u8981 2-3 \u5C0F\u65F6\uFF0C\u5177\u4F53\u53D6\u51B3\u4E8E\u60A8\u7684\u673A\u5668\u548C\u5E26\u5BBD\u3002\u5982\u679C\u60A8\u4E0D\u60F3\u81EA\u5DF1\u7ECF\u5386\u8FD9\u4E2A\u6F2B\u957F\u7684\u8FC7\u7A0B\uFF0C\u6211\u4EEC\u5728 Hub \u4E0A\u63D0\u4F9B\u8FC7\u6EE4\u540E\u7684\u6570\u636E\u96C6\u4F9B\u60A8\u4E0B\u8F7D\uFF1A"),zt=m(),q(Bs.$$.fragment),Us=m(),q(Ws.$$.fragment),pe=m(),q(Xs.$$.fragment),_t=m(),gs=_("p"),Pt=n("\u8BA9\u6211\u4EEC\u770B\u4E00\u4E2A\u6765\u81EA\u6570\u636E\u96C6\u7684\u4F8B\u5B50\u3002\u6211\u4EEC\u5C06\u53EA\u663E\u793A\u6BCF\u4E2A\u5B57\u6BB5\u7684\u524D 200 \u4E2A\u5B57\u7B26\uFF1A"),Ks=m(),q(Vs.$$.fragment),us=m(),q(ie.$$.fragment),He=m(),Ys=_("p"),ba=n("\u6211\u4EEC\u53EF\u4EE5\u770B\u5230 "),_e=_("code"),ga=n("content"),ka=n(" \u5B57\u6BB5\u5305\u542B\u6211\u4EEC\u5E0C\u671B\u6211\u4EEC\u7684\u6A21\u578B\u8BAD\u7EC3\u7684\u4EE3\u7801\u3002\u73B0\u5728\u6211\u4EEC\u6709\u4E86\u4E00\u4E2A\u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u9700\u8981\u9884\u5904\u7406\u6587\u672C\uFF0C\u4F7F\u5176\u91C7\u7528\u9002\u5408\u9884\u8BAD\u7EC3\u7684\u683C\u5F0F\u3002"),ct=m(),ms=_("h2"),Tt=n("\u51C6\u5907\u6570\u636E\u96C6"),ls=m(),q(ce.$$.fragment),Ie=m(),Ne=_("p"),ja=n("\u7B2C\u4E00\u6B65\u662F\u5BF9\u6570\u636E\u8FDB\u884C\u6807\u8BB0\uFF0C\u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u5C06\u5176\u7528\u4E8E\u8BAD\u7EC3\u3002\u7531\u4E8E\u6211\u4EEC\u7684\u76EE\u6807\u4E3B\u8981\u662F\u81EA\u52A8\u5B8C\u6210\u77ED\u51FD\u6570\u8C03\u7528\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u4FDD\u6301\u4E0A\u4E0B\u6587\u5927\u5C0F\u76F8\u5BF9\u8F83\u5C0F\u3002\u8FD9\u6837\u505A\u7684\u597D\u5904\u662F\u6211\u4EEC\u53EF\u4EE5\u66F4\u5FEB\u5730\u8BAD\u7EC3\u6A21\u578B\u5E76\u4E14\u5B83\u9700\u8981\u7684\u5185\u5B58\u663E\u7740\u51CF\u5C11\u3002\u5982\u679C\u60A8\u7684\u5E94\u7528\u7A0B\u5E8F\u62E5\u6709\u66F4\u591A\u4E0A\u4E0B\u6587\u5F88\u91CD\u8981\uFF08\u4F8B\u5982\uFF0C\u5982\u679C\u60A8\u5E0C\u671B\u6A21\u578B\u57FA\u4E8E\u5177\u6709\u51FD\u6570\u5B9A\u4E49\u7684\u6587\u4EF6\u7F16\u5199\u5355\u5143\u6D4B\u8BD5\uFF09\uFF0C\u8BF7\u786E\u4FDD\u589E\u52A0\u8BE5\u6570\u91CF\uFF0C\u4F46\u8BF7\u8BB0\u4F4F\uFF0C\u8FD9\u9700\u8981\u66F4\u5927\u7684 GPU \u5185\u5B58\u5360\u7528\u3002\u73B0\u5728\uFF0C\u8BA9\u6211\u4EEC\u5C06\u4E0A\u4E0B\u6587\u5927\u5C0F\u56FA\u5B9A\u4E3A 128 \u4E2A\u6807\u8BB0\uFF0C\u800C\u4E0D\u662F GPT-2 \u6216 GPT-3 \u4E2D\u5206\u522B\u4F7F\u7528\u7684 1,024 \u6216 2,048 \u4E2A\u6807\u8BB0\u3002"),Se=m(),rs=_("p"),wa=n("\u5927\u591A\u6570\u6587\u6863\u5305\u542B\u8D85\u8FC7 128 \u4E2A\u6807\u8BB0\uFF0C\u56E0\u6B64\u7B80\u5355\u5730\u5C06\u8F93\u5165\u622A\u65AD\u5230\u6700\u5927\u957F\u5EA6\u5C06\u6D88\u9664\u6211\u4EEC\u6570\u636E\u96C6\u7684\u5F88\u5927\u4E00\u90E8\u5206\u3002\u76F8\u53CD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 "),ue=_("code"),ya=n("return_overflowing_tokens"),va=n(" \u6807\u8BB0\u6574\u4E2A\u8F93\u5165\u5E76\u5C06\u5176\u5206\u6210\u51E0\u4E2A\u5757\u7684\u9009\u9879\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728"),me=_("a"),fe=n("\u7B2C\u516D\u7AE0"),Dt=n(". \u6211\u4EEC\u8FD8\u5C06\u4F7F\u7528 "),zs=_("code"),Ct=n("return_length"),Re=n(" \u9009\u9879\u81EA\u52A8\u8FD4\u56DE\u6BCF\u4E2A\u521B\u5EFA\u7684\u5757\u7684\u957F\u5EA6\u3002\u901A\u5E38\u6700\u540E\u4E00\u4E2A\u5757\u4F1A\u5C0F\u4E8E\u4E0A\u4E0B\u6587\u5927\u5C0F\uFF0C\u6211\u4EEC\u4F1A\u53BB\u6389\u8FD9\u4E9B\u5757\u4EE5\u907F\u514D\u586B\u5145\u95EE\u9898\uFF1B\u56E0\u4E3A\u65E0\u8BBA\u5982\u4F55\u6211\u4EEC\u90FD\u6709\u5927\u91CF\u6570\u636E\u3002"),Ot=m(),ks=_("div"),fs=_("img"),js=m(),de=_("img"),Gt=m(),Be=_("p"),ut=n("\u8BA9\u6211\u4EEC\u901A\u8FC7\u67E5\u770B\u524D\u4E24\u4E2A\u793A\u4F8B\u6765\u786E\u5207\u4E86\u89E3\u8FD9\u662F\u5982\u4F55\u5DE5\u4F5C\u7684\uFF1A"),Mt=m(),q(he.$$.fragment),mt=m(),q(ds.$$.fragment),ft=m(),os=_("p"),Ft=n("\u6211\u4EEC\u53EF\u4EE5\u770B \u5230\uFF0C\u4ECE\u8FD9\u4E24\u4E2A\u793A\u4F8B\u4E2D\u6211\u4EEC\u603B\u5171\u5F97\u5230\u4E86 34 \u4E2A\u7247\u6BB5\u3002\u67E5\u770B\u5757\u957F\u5EA6\uFF0C\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u4E24\u4E2A\u6587\u6863\u672B\u5C3E\u7684\u5757\u90FD\u5C11\u4E8E 128 \u4E2A\u6807\u8BB0\uFF08\u5206\u522B\u4E3A 117 \u548C 41\uFF09\u3002\u8FD9\u4E9B\u4EC5\u4EE3\u8868\u6211\u4EEC\u62E5\u6709\u7684\u6570\u636E\u96C6\u7684\u4E00\u5C0F\u90E8\u5206\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u5B89\u5168\u5730\u5C06\u5B83\u4EEC\u6254\u6389\u3002\u901A\u8FC7 "),ws=_("code"),Ea=n("overflow_to_sample_mapping"),dt=n(" \u5B57\u6BB5\uFF0C\u6211\u4EEC\u8FD8\u53EF\u4EE5\u91CD\u5EFA\u54EA\u4E9B\u5757\u5C5E\u4E8E\u54EA\u4E9B\u8F93\u5165\u6837\u672C\u3002"),Lt=m(),ps=_("p"),Ht=n("\u901A\u8FC7\u8FD9\u4E2A\u64CD\u4F5C\uFF0C\u6211\u4EEC\u4F7F\u7528\u4E86\u4E00\u4E2A\u65B9\u4FBF\u7684\u{1F917} Datasets \u4E2D\u7684"),Ps=_("code"),It=n("Dataset.map()"),Ue=n(" \u51FD\u6570\uFF0C\u5C31\u662F\u4E0D\u9700\u8981\u4E00\u5BF9\u4E00\u7684\u6620\u5C04\uFF1B\u6B63\u5982\u6211\u4EEC\u5728"),We=_("a"),Nt=n("\u7B2C\u4E09\u8282"),$e=n(",\u6211\u4EEC\u53EF\u4EE5\u521B\u5EFA\u5177\u6709\u6BD4\u8F93\u5165\u6279\u6B21\u66F4\u591A\u6216\u66F4\u5C11\u5143\u7D20\u7684\u6279\u6B21\u3002\u8FD9\u5728\u6267\u884C\u66F4\u6539\u5143\u7D20\u6570\u91CF\u7684\u6570\u636E\u589E\u5F3A\u6216\u6570\u636E\u8FC7\u6EE4\u7B49\u64CD\u4F5C\u65F6\u975E\u5E38\u6709\u7528\u3002\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\uFF0C\u5F53\u5C06\u6BCF\u4E2A\u5143\u7D20\u6807\u8BB0\u4E3A\u6307\u5B9A\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u5757\u65F6\uFF0C\u6211\u4EEC\u4ECE\u6BCF\u4E2A\u6587\u6863\u4E2D\u521B\u5EFA\u4E86\u8BB8\u591A\u6837\u672C\u3002\u6211\u4EEC\u53EA\u9700\u8981\u786E\u4FDD\u5220\u9664\u73B0\u6709\u7684\u5217\uFF0C\u56E0\u4E3A\u5B83\u4EEC\u7684\u5927\u5C0F\u5B58\u5728\u51B2\u7A81\u3002\u5982\u679C\u6211\u4EEC\u60F3\u4FDD\u7559\u5B83\u4EEC\uFF0C\u6211\u4EEC\u53EF\u4EE5\u9002\u5F53\u5730\u91CD\u590D\u5B83\u4EEC\uFF0C\u5E76\u5728"),Xe=_("code"),be=n("Dataset.map()"),St=n(" \u8C03\u7528\u4E2D\u8FD4\u56DE\u5B83\u4EEC:"),a=m(),q(k.$$.fragment),xa=m(),q(Ke.$$.fragment),za=m(),ge=_("p"),Qa=n("\u6211\u4EEC\u73B0\u5728\u6709 1670 \u4E07\u4E2A\u793A\u4F8B\uFF0C\u6BCF\u4E2A\u793A\u4F8B\u6709 128 \u4E2Atokens \uFF0C\u603B\u5171\u76F8\u5F53\u4E8E\u5927\u7EA6 21 \u4EBF\u4E2Atokens \u3002\u4F5C\u4E3A\u53C2\u8003\uFF0COpenAI \u7684 GPT-3 \u548C Codex \u6A21\u578B\u5206\u522B\u5728 300 \u548C 1000 \u4EBF\u4E2Atokens \u4E0A\u8BAD\u7EC3\uFF0C\u5176\u4E2D Codex \u6A21\u578B\u4ECE GPT-3 \u68C0\u67E5\u70B9\u521D\u59CB\u5316\u3002\u6211\u4EEC\u5728\u672C\u8282\u4E2D\u7684\u76EE\u6807\u4E0D\u662F\u4E0E\u8FD9\u4E9B\u6A21\u578B\u7ADE\u4E89\uFF0C\u8FD9\u4E9B\u6A21\u578B\u53EF\u4EE5\u751F\u6210\u957F\u800C\u8FDE\u8D2F\u7684\u6587\u672C\uFF0C\u800C\u662F\u521B\u5EFA\u4E00\u4E2A\u7F29\u5C0F\u7248\u672C\uFF0C\u4E3A\u6570\u636E\u79D1\u5B66\u5BB6\u63D0\u4F9B\u5FEB\u901F\u81EA\u52A8\u5B8C\u6210\u529F\u80FD\u3002"),X=m(),ht=_("p"),sl=n("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u4E86\u6570\u636E\u96C6\uFF0C\u8BA9\u6211\u4EEC\u8BBE\u7F6E\u6A21\u578B\uFF01"),Pa=m(),q(ke.$$.fragment),Ta=m(),Ve=_("h2"),el=n("\u521D\u59CB\u5316\u65B0\u6A21\u578B"),Da=m(),Ts=_("p"),tl=n("\u6211\u4EEC\u7684\u7B2C\u4E00\u6B65\u662F\u65B0\u521D\u59CB\u5316\u4E00\u4E2A GPT-2 \u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5BF9\u6211\u4EEC\u7684\u6A21\u578B\u4F7F\u7528\u4E0E\u5C0F\u578B GPT-2 \u6A21\u578B\u76F8\u540C\u7684\u914D\u7F6E\uFF0C\u56E0\u6B64\u6211\u4EEC\u52A0\u8F7D\u9884\u8BAD\u7EC3\u914D\u7F6E\uFF0C\u786E\u4FDD\u5206\u8BCD\u5668\u5927\u5C0F\u4E0E\u6A21\u578B\u8BCD\u6C47\u91CF\u5927\u5C0F\u5339\u914D\u5E76\u8BBE\u7F6E "),Zs=_("code"),al=n("bos"),ll=n(" \u548C "),Rt=_("code"),Ye=n("eos"),nl=n(" \uFF08\u5E8F\u5217\u7684\u5F00\u59CB\u548C\u7ED3\u675F\uFF09\u4EE4\u724C ID\uFF1A"),Ca=m(),vs.c(),Ds=m(),Cs=_("p"),rl=n("\u6211\u4EEC\u7684\u6A21\u578B\u6709 1.24 \u4EBF\u4E2A\u53C2\u6570\uFF0C\u6211\u4EEC\u5FC5\u987B\u5BF9\u5176\u8FDB\u884C\u8C03\u6574\u3002\u5728\u5F00\u59CB\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u8D1F\u8D23\u521B\u5EFA\u6279\u6B21\u7684\u6570\u636E\u6574\u7406\u5668\u3002\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528 "),Bt=_("code"),ol=n("DataCollatorForLanguageModeling"),Ze=n(" \uFF0C\u5B83\u662F\u4E13\u4E3A\u8BED\u8A00\u5EFA\u6A21\u800C\u8BBE\u8BA1\uFF08\u987E\u540D\u601D\u4E49\uFF09\u3002\u9664\u4E86\u5806\u53E0\u548C\u586B\u5145\u6279\u6B21\uFF0C\u5B83\u8FD8\u8D1F\u8D23\u521B\u5EFA\u8BED\u8A00\u6A21\u578B\u6807\u7B7E\u2014\u2014\u5728\u56E0\u679C\u8BED\u8A00\u5EFA\u6A21\u4E2D\uFF0C\u8F93\u5165\u4E5F\u7528\u4F5C\u6807\u7B7E\uFF08\u53EA\u662F\u79FB\u52A8\u4E86\u4E00\u4E2A\u5143\u7D20\uFF09\uFF0C\u5E76\u4E14\u8FD9\u4E2A\u6570\u636E\u6574\u7406\u5668\u5728\u8BAD\u7EC3\u671F\u95F4\u5373\u65F6\u521B\u5EFA\u5B83\u4EEC\uFF0C\u6240\u4EE5\u6211\u4EEC\u4E0D\u9700\u8981\u590D\u5236 "),Ut=_("code"),pl=n("input_ids"),Js=n("\u3002"),Oa=m(),Os=_("p"),il=n("\u6CE8\u610F "),Wt=_("code"),Je=n("DataCollatorForLanguageModeling"),_l=n(" \u652F\u6301\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21 (MLM) \u548C\u56E0\u679C\u8BED\u8A00\u5EFA\u6A21 (CLM)\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B\u5B83\u4E3A MLM \u51C6\u5907\u6570\u636E\uFF0C\u4F46\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8BBE\u7F6E"),Xt=_("code"),Kt=n("mlm=False"),cl=n("\u53C2\u6570\u5207\u6362\u5230 CLM \uFF1A"),Aa=m(),we.c(),ul=m(),ml=_("p"),En=n("\u8BA9\u6211\u4EEC\u770B\u4E00\u4E2A\u4F8B\u5B50\uFF1A"),Bl=m(),q(Ga.$$.fragment),Ul=m(),ve.c(),fl=m(),dl=_("p"),xn=n("\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u793A\u4F8B\u5DF2\u7ECF\u5806\u53E0\u5728\u4E00\u8D77\uFF0C\u5E76\u4E14\u6240\u6709\u5F20\u91CF\u90FD\u5177\u6709\u76F8\u540C\u7684\u5F62\u72B6\u3002"),Wl=m(),Q&&Q.c(),hl=m(),q(Vt.$$.fragment),Xl=m(),$l=_("p"),zn=n("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u5B9E\u9645\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u7684\u4E00\u5207\u4E86\u2014\u2014\u6BD5\u7ADF\u8FD9\u4E0D\u662F\u90A3\u4E48\u591A\u5DE5\u4F5C\uFF01\u5728\u6211\u4EEC\u5F00\u59CB\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u5E94\u8BE5\u767B\u5F55 Hugging Face\u3002\u5982\u679C\u60A8\u5728\u7B14\u8BB0\u672C\u4E0A\u5DE5\u4F5C\uFF0C\u5219\u53EF\u4EE5\u4F7F\u7528\u4EE5\u4E0B\u5B9E\u7528\u7A0B\u5E8F\u529F\u80FD\uFF1A"),Kl=m(),q(Ma.$$.fragment),Vl=m(),bl=_("p"),Pn=n("\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u767B\u5F55\u51ED\u636E\u3002"),Yl=m(),gl=_("p"),Tn=n("\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),Zl=m(),q(Fa.$$.fragment),Jl=m(),Ee.c(),kl=m(),q(Yt.$$.fragment),Ql=m(),q(Zt.$$.fragment),sn=m(),La=_("h2"),Dn=n("\u4F7F\u7528\u7BA1\u9053\u751F\u6210\u4EE3\u7801"),en=m(),Jt=_("p"),Cn=n("\u73B0\u5728\u662F\u5173\u952E\u7684\u90E8\u5206\uFF1A\u8BA9\u6211\u4EEC\u770B\u770B\u7ECF\u8FC7\u8BAD\u7EC3\u7684\u6A21\u578B\u7684\u5B9E\u9645\u6548\u679C\u5982\u4F55\uFF01\u6211\u4EEC\u53EF\u4EE5\u5728\u65E5\u5FD7\u4E2D\u770B\u5230\u635F\u5931\u7A33\u6B65\u4E0B\u964D\uFF0C\u4F46\u4E3A\u4E86\u8BA9\u6A21\u578B\u8FDB\u884C\u6D4B\u8BD5\uFF0C\u8BA9\u6211\u4EEC\u770B\u770B\u5B83\u5728\u67D0\u4E9B\u6D4B\u8BD5\u4E0A\u7684\u8868\u73B0\u5982\u4F55\u3002\u4E3A\u6B64\uFF0C\u6211\u4EEC\u5C06\u6A21\u578B\u5305\u88C5\u5728\u6587\u672C\u751F\u6210\u4E2D\u7684"),Ol=_("code"),On=n("pipeline"),An=n(" \uFF0C\u5982\u679C\u6709\u53EF\u7528\u7684\uFF0C\u6211\u4EEC\u4F1A\u5C06\u5B83\u653E\u5728 GPU \u4E0A\u8FDB\u884C\u5FEB\u901F\u751F\u6210\uFF1A"),tn=m(),ze.c(),jl=m(),wl=_("p"),Gn=n("\u8BA9\u6211\u4EEC\u4ECE\u521B\u5EFA\u6563\u70B9\u56FE\u7684\u7B80\u5355\u4EFB\u52A1\u5F00\u59CB\uFF1A"),an=m(),q(Ha.$$.fragment),ln=m(),q(Ia.$$.fragment),nn=m(),Qe=_("p"),Mn=n("\u7ED3\u679C\u770B\u8D77\u6765\u662F\u6B63\u786E\u7684\u3002\u5B83\u4E5F\u9002\u7528\u4E8E "),Al=_("code"),Fn=n("pandas"),Ln=n(" \u7C7B\u578B\uFF1F\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u4F7F\u7528\u4E24\u4E2A\u6570\u7EC4\u53EF\u4EE5\u521B\u5EFA\u4E00\u4E2A "),Gl=_("code"),Hn=n("DataFrame"),In=n(" \uFF1A"),rn=m(),q(Na.$$.fragment),on=m(),q(Sa.$$.fragment),pn=m(),st=_("p"),Nn=n("\u5F88\u597D\uFF0C\u8FD9\u662F\u6B63\u786E\u7684\u7B54\u6848\u2014\u2014\u5C3D\u7BA1\u5B83\u968F\u540E\u518D\u6B21\u63D2\u5165\u4E86\u5217 "),Ml=_("code"),Sn=n("x"),Rn=n(" \u3002\u7531\u4E8E\u751F\u6210\u7684token\u6570\u91CF\u6709\u9650\uFF0C\u4EE5\u4E0B "),Fl=_("code"),Bn=n("for"),Un=n(" \u5FAA\u73AF\u88AB\u5207\u65AD\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u53EF\u4EE5\u505A\u4E00\u4E9B\u66F4\u590D\u6742\u7684\u4E8B\u60C5\u5E76\u8BA9\u6A21\u578B\u5E2E\u52A9\u6211\u4EEC\u5206\u7EC4\u64CD\u4F5C\uFF1A"),_n=m(),q(Ra.$$.fragment),cn=m(),q(Ba.$$.fragment),un=m(),Qt=_("p"),Wn=n("\u4E0D\u9519;\u8FD9\u662F\u6B63\u786E\u7684\u505A\u6CD5\u3002\u6700\u540E\uFF0C\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u4E5F\u53EF\u4EE5\u5C06\u5176\u7528\u4E8E "),Ll=_("code"),Xn=n("scikit-learn"),Kn=n(" \u5E76\u5EFA\u7ACB\u4E00\u4E2A\u968F\u673A\u68EE\u6797\u6A21\u578B\uFF1A"),mn=m(),q(Ua.$$.fragment),fn=m(),q(Wa.$$.fragment),dn=m(),$t.c(),yl=m(),ss&&ss.c(),vl=qn(),this.h()},l(s){const i=no('[data-svelte="svelte-1phssyn"]',document.head);l=c(i,"META",{name:!0,content:!0}),i.forEach(e),d=f(s),E(p.$$.fragment,s),h=f(s),y=c(s,"H1",{id:!0});var Hl=u(y);j=r(Hl,"\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u56E0\u679C\u8BED\u8A00\u6A21\u578B"),Hl.forEach(e),v=f(s),w.l(s),D=f(s),G=c(s,"P",{});var sa=u(G);L=r(sa,"\u5230\u76EE\u524D\u4E3A\u6B62\uFF0C\u6211\u4EEC\u4E3B\u8981\u4F7F\u7528\u9884\u8BAD\u7EC3\u6A21\u578B\uFF0C\u5E76\u901A\u8FC7\u91CD\u7528\u9884\u8BAD\u7EC3\u7684\u6743\u91CD\u6765\u9488\u5BF9\u65B0\u7528\u4F8B\u5BF9\u5B83\u4EEC\u8FDB\u884C\u5FAE\u8C03\u3002\u6B63\u5982\u6211\u4EEC\u5728"),$=c(sa,"A",{href:!0});var Il=u($);M=r(Il,"\u7B2C\u4E00\u7AE0"),Il.forEach(e),I=r(sa,", \u8FD9\u901A\u5E38\u79F0\u4E3A\u8FC1\u79FB\u5B66\u4E60\uFF0C\u8FD9\u662F\u5C06 Transformer \u6A21\u578B\u5E94\u7528\u4E8E\u5927\u591A\u6570\u6807\u8BB0\u6570\u636E\u7A00\u758F\u7684\u73B0\u5B9E\u4E16\u754C\u7528\u4F8B\u7684\u975E\u5E38\u6210\u529F\u7684\u7B56\u7565\u3002\u5728\u672C\u7AE0\u4E2D\uFF0C\u6211\u4EEC\u5C06\u91C7\u7528\u4E0D\u540C\u7684\u65B9\u6CD5\u5E76\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u4E00\u4E2A\u5168\u65B0\u7684\u6A21\u578B\u3002\u5982\u679C\u60A8\u6709\u5927\u91CF\u6570\u636E\u5E76\u4E14\u5B83\u4E0E\u7528\u4E8E\u53EF\u7528\u6A21\u578B\u7684\u9884\u8BAD\u7EC3\u6570\u636E\u6709\u5F88\u5927\u4E0D\u540C\uFF0C\u90A3\u4E48\u8FD9\u662F\u4E00\u4E2A\u5F88\u597D\u7684\u65B9\u6CD5\u3002\u7136\u800C\uFF0C\u5B83\u4E5F\u9700\u8981\u66F4\u591A\u7684\u8BA1\u7B97\u8D44\u6E90\u6765\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\uFF0C\u800C\u4E0D\u4EC5\u4EC5\u662F\u5FAE\u8C03\u73B0\u6709\u7684\u6A21\u578B\u3002\u8BAD\u7EC3\u65B0\u6A21\u578B\u6709\u610F\u4E49\u7684\u793A\u4F8B\u5305\u62EC\u7531\u97F3\u7B26\u3001\u5206\u5B50\u5E8F\u5217\uFF08\u5982 DNA\uFF09\u6216\u7F16\u7A0B\u8BED\u8A00\u7EC4\u6210\u7684\u6570\u636E\u96C6\u3002\u540E\u8005\u6700\u8FD1\u53D7\u5230\u5173\u6CE8\uFF0C\u8FD9\u8981\u5F52\u529F\u4E8E TabNine \u548C GitHub \u7684 Copilot \u7B49\u5DE5\u5177\uFF0C\u5B83\u4EEC\u7531 OpenAI \u7684 Codex \u6A21\u578B\u63D0\u4F9B\u652F\u6301\uFF0C\u53EF\u4EE5\u751F\u6210\u957F\u4EE3\u7801\u5E8F\u5217\u3002\u8FD9\u79CD\u6587\u672C\u751F\u6210\u4EFB\u52A1\u6700\u597D\u4F7F\u7528\u81EA\u56DE\u5F52\u6216\u56E0\u679C\u8BED\u8A00\u6A21\u578B\uFF08\u4F8B\u5982 GPT-2\uFF09\u6765\u89E3\u51B3\u3002"),sa.forEach(e),R=f(s),A=c(s,"P",{});var As=u(A);B=r(As,"\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u6784\u5EFA\u4EE3\u7801\u751F\u6210\u6A21\u578B\u7684\u7F29\u5C0F\u7248\u672C\uFF1A\u6211\u4EEC\u5C06\u4F7F\u7528 Python \u4EE3\u7801\u7684\u5B50\u96C6\u4E13\u6CE8\u4E8E\u5355\u884C\u5B8C\u6210\u800C\u4E0D\u662F\u5B8C\u6574\u7684\u51FD\u6570\u6216\u7C7B\u3002\u5728 Python \u4E2D\u5904\u7406\u6570\u636E\u65F6\uFF0C\u60A8\u4F1A\u7ECF\u5E38\u63A5\u89E6 Python \u6570\u636E\u79D1\u5B66\u5806\u6808\uFF0C\u5305\u62EC "),W=c(As,"CODE",{});var ql=u(W);F=r(ql,"matplotlib"),ql.forEach(e),N=r(As," , "),S=c(As,"CODE",{});var El=u(S);Y=r(El,"seaborn"),El.forEach(e),Z=r(As," , "),K=c(As,"CODE",{});var xl=u(K);es=r(xl,"pandas"),xl.forEach(e),is=r(As," \uFF0C \u548C "),C=c(As,"CODE",{});var Nl=u(C);U=r(Nl,"scikit-learn"),Nl.forEach(e),Pe=r(As," \u5E93\u3002\u5728\u4F7F\u7528\u8FD9\u4E9B\u6846\u67B6\u65F6\uFF0C\u901A\u5E38\u9700\u8981\u67E5\u627E\u7279\u5B9A\u7684\u547D\u4EE4\uFF0C\u56E0\u6B64\u5982\u679C\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u6765\u4E3A\u6211\u4EEC\u5B8C\u6210\u8FD9\u4E9B\u8C03\u7528\uFF0C\u90A3\u5C31\u592A\u597D\u4E86\u3002"),As.forEach(e),qs=f(s),E(hs.$$.fragment,s),Es=f(s),J=c(s,"P",{});var et=u(J);Te=r(et,"\u5728"),De=c(et,"A",{href:!0});var Sl=u(De);tt=r(Sl,"\u7B2C\u516D\u7AE0"),Sl.forEach(e),pa=r(et," \u6211\u4EEC\u521B\u5EFA\u4E86\u4E00\u4E2A\u9AD8\u6548\u7684\u5206\u8BCD\u5668\u6765\u5904\u7406 Python \u6E90\u4EE3\u7801\uFF0C\u4F46\u6211\u4EEC\u4ECD\u7136\u9700\u8981\u4E00\u4E2A\u5927\u89C4\u6A21\u6570\u636E\u96C6\u6765\u9884\u8BAD\u7EC3\u6A21\u578B\u3002\u5728\u8FD9\u91CC\uFF0C\u6211\u4EEC\u5C06\u6211\u4EEC\u7684\u5206\u8BCD\u5668\u5E94\u7528\u5230\u6E90\u81EA GitHub \u5B58\u50A8\u5E93\u7684 Python \u4EE3\u7801\u8BED\u6599\u5E93\u3002\u7136\u540E\u6211\u4EEC\u5C06\u4F7F\u7528 "),at=c(et,"CODE",{});var Rl=u(at);lt=r(Rl,"Trainer"),Rl.forEach(e),ia=r(et," API \u548C \u{1F917} Accelerate \u6765\u8BAD\u7EC3\u6A21\u578B\u3002\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427\uFF01"),et.forEach(e),bt=f(s),ts=c(s,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),u(ts).forEach(e),nt=f(s),V=c(s,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),u(V).forEach(e),Qs=f(s),Gs=c(s,"P",{});var ea=u(Gs);gt=r(ea,"\u8FD9\u5B9E\u9645\u4E0A\u5C55\u793A\u4E86\u4F7F\u7528\u672C\u8282\u4E2D\u8BAD\u7EC3\u5E76\u4E0A\u4F20\u5230 Hub \u7684\u6A21\u578B\u3002\u4F60\u53EF\u4EE5\u5728"),_s=c(ea,"A",{href:!0,rel:!0});var ir=u(_s);kt=r(ir,"\u8FD9\u91CC"),ir.forEach(e),Oe=r(ea,"\u627E\u5230\u3002\u8BF7\u6CE8\u610F\uFF0C\u7531\u4E8E\u5728\u6587\u672C\u751F\u6210\u8FC7\u7A0B\u4E2D\u53D1\u751F\u4E86\u4E00\u4E9B\u968F\u673A\u5316\uFF0C\u60A8\u53EF\u80FD\u4F1A\u5F97\u5230\u7565\u6709\u4E0D\u540C\u7684\u7ED3\u679C\u3002"),ea.forEach(e),jt=f(s),Ms=c(s,"H2",{id:!0});var _r=u(Ms);$s=r(_r,"\u6536\u96C6\u6570\u636E"),_r.forEach(e),Ae=f(s),ns=c(s,"P",{});var ta=u(ns);ca=r(ta,"Python \u4EE3\u7801\u53EF\u4EE5\u4ECE GitHub \u7B49\u4EE3\u7801\u5B58\u50A8\u5E93\u4E2D\u83B7\u5F97\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u6293\u53D6\u6BCF\u4E2A Python \u5B58\u50A8\u5E93\u6765\u4F7F\u7528\u5B83\u4EEC\u6765\u521B\u5EFA\u6570\u636E\u96C6\u3002\u8FD9\u662F\u5728"),xs=c(ta,"A",{href:!0,rel:!0});var cr=u(xs);ua=r(cr,"Transformers textbook"),cr.forEach(e),ma=r(ta,"\u9884\u8BAD\u7EC3\u5927\u578B\u7684GPT-2 \u6A21\u578B\u3002\u4F7F\u7528\u5927\u7EA6 180 GB \u7684 GitHub \u8F6C\u50A8\uFF0C\u5176\u4E2D\u5305\u542B\u5927\u7EA6 2000 \u4E07\u4E2A Python \u6587\u4EF6\uFF0C\u79F0\u4E3A "),se=c(ta,"CODE",{});var ur=u(se);fa=r(ur,"codeparrot"),ur.forEach(e),wt=r(ta," \uFF0C\u4F5C\u8005\u6784\u5EFA\u4E86\u4E00\u4E2A\u6570\u636E\u96C6\uFF0C\u7136\u540E\u5728"),as=c(ta,"A",{href:!0,rel:!0});var mr=u(as);da=r(mr,"Hugging Face Hub"),mr.forEach(e),rt=r(ta,"\u4E0A\u5206\u4EAB\u51FA\u6765\u4E86."),ta.forEach(e),yt=f(s),Fs=c(s,"P",{});var bn=u(Fs);ot=r(bn,"\u7136\u800C\uFF0C\u5BF9\u5B8C\u6574\u8BED\u6599\u5E93\u7684\u8BAD\u7EC3\u65E2\u8017\u65F6\u53C8\u8D39\u529B\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u4E0E Python \u6570\u636E\u79D1\u5B66\u5806\u6808\u76F8\u5173\u7684\u6570\u636E\u96C6\u5B50\u96C6\u3002\u6240\u4EE5\uFF0C\u8BA9\u6211\u4EEC\u5F00\u59CB\u8FC7\u6EE4 "),pt=c(bn,"CODE",{});var fr=u(pt);ha=r(fr,"codeparrot"),fr.forEach(e),vt=r(bn," \u5305\u542B\u6B64\u5806\u6808\u4E2D\u4EFB\u4F55\u5E93\u7684\u6240\u6709\u6587\u4EF6\u7684\u6570\u636E\u96C6\u3002\u7531\u4E8E\u6570\u636E\u96C6\u7684\u592A\u5927\uFF0C\u6211\u4EEC\u5E0C\u671B\u907F\u514D\u4E0B\u8F7D\u5B83\uFF1B\u56E0\u6B64\u53CD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u6D41\u529F\u80FD\u6765\u52A8\u6001\u8FC7\u6EE4\u5B83\u3002\u4E3A\u4E86\u4F7F\u7528\u524D\u9762\u63D0\u5230\u7684\u5E93\u8FC7\u6EE4\u4EE3\u7801\u793A\u4F8B\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u4EE5\u4E0B\u51FD\u6570\uFF1A"),bn.forEach(e),Ls=f(s),E(Hs.$$.fragment,s),ee=f(s),Ge=c(s,"P",{});var dr=u(Ge);qt=r(dr,"\u8BA9\u6211\u4EEC\u7528\u4E24\u4E2A\u4F8B\u5B50\u6765\u6D4B\u8BD5\u4E00\u4E0B\uFF1A"),dr.forEach(e),Is=f(s),E(Ns.$$.fragment,s),te=f(s),E(ae.$$.fragment,s),it=f(s),bs=c(s,"P",{});var hr=u(bs);Et=r(hr,"\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u5B83\u6765\u521B\u5EFA\u4E00\u4E2A\u51FD\u6570\u6765\u6D41\u5F0F\u4F20\u8F93\u6570\u636E\u96C6\u5E76\u8FC7\u6EE4\u6211\u4EEC\u60F3\u8981\u7684\u5143\u7D20\uFF1A"),hr.forEach(e),cs=f(s),E(le.$$.fragment,s),Me=f(s),Fe=c(s,"P",{});var $r=u(Fe);$a=r($r,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7B80\u5355\u5730\u5C06\u6B64\u51FD\u6570\u5E94\u7528\u4E8E\u6D41\u6570\u636E\u96C6\uFF1A"),$r.forEach(e),ne=f(s),E(re.$$.fragment,s),xt=f(s),E(Ss.$$.fragment,s),Rs=f(s),oe=c(s,"P",{});var br=u(oe);Le=r(br,"\u8FD9\u7ED9\u6211\u4EEC\u7559\u4E0B\u4E86\u5927\u7EA6 3% \u7684\u539F\u59CB\u6570\u636E\u96C6\uFF0C\u8FD9\u4E2A\u6570\u636E\u96C6\u4ECD\u7136\u76F8\u5F53\u53EF\u89C2\u2014\u2014\u7ED3\u679C\u6570\u636E\u96C6\u6709 6 GB\uFF0C\u5305\u542B 600,000 \u4E2A Python \u811A\u672C\uFF01\u8FC7\u6EE4\u5B8C\u6574\u6570\u636E\u96C6\u53EF\u80FD\u9700\u8981 2-3 \u5C0F\u65F6\uFF0C\u5177\u4F53\u53D6\u51B3\u4E8E\u60A8\u7684\u673A\u5668\u548C\u5E26\u5BBD\u3002\u5982\u679C\u60A8\u4E0D\u60F3\u81EA\u5DF1\u7ECF\u5386\u8FD9\u4E2A\u6F2B\u957F\u7684\u8FC7\u7A0B\uFF0C\u6211\u4EEC\u5728 Hub \u4E0A\u63D0\u4F9B\u8FC7\u6EE4\u540E\u7684\u6570\u636E\u96C6\u4F9B\u60A8\u4E0B\u8F7D\uFF1A"),br.forEach(e),zt=f(s),E(Bs.$$.fragment,s),Us=f(s),E(Ws.$$.fragment,s),pe=f(s),E(Xs.$$.fragment,s),_t=f(s),gs=c(s,"P",{});var gr=u(gs);Pt=r(gr,"\u8BA9\u6211\u4EEC\u770B\u4E00\u4E2A\u6765\u81EA\u6570\u636E\u96C6\u7684\u4F8B\u5B50\u3002\u6211\u4EEC\u5C06\u53EA\u663E\u793A\u6BCF\u4E2A\u5B57\u6BB5\u7684\u524D 200 \u4E2A\u5B57\u7B26\uFF1A"),gr.forEach(e),Ks=f(s),E(Vs.$$.fragment,s),us=f(s),E(ie.$$.fragment,s),He=f(s),Ys=c(s,"P",{});var gn=u(Ys);ba=r(gn,"\u6211\u4EEC\u53EF\u4EE5\u770B\u5230 "),_e=c(gn,"CODE",{});var kr=u(_e);ga=r(kr,"content"),kr.forEach(e),ka=r(gn," \u5B57\u6BB5\u5305\u542B\u6211\u4EEC\u5E0C\u671B\u6211\u4EEC\u7684\u6A21\u578B\u8BAD\u7EC3\u7684\u4EE3\u7801\u3002\u73B0\u5728\u6211\u4EEC\u6709\u4E86\u4E00\u4E2A\u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u9700\u8981\u9884\u5904\u7406\u6587\u672C\uFF0C\u4F7F\u5176\u91C7\u7528\u9002\u5408\u9884\u8BAD\u7EC3\u7684\u683C\u5F0F\u3002"),gn.forEach(e),ct=f(s),ms=c(s,"H2",{id:!0});var jr=u(ms);Tt=r(jr,"\u51C6\u5907\u6570\u636E\u96C6"),jr.forEach(e),ls=f(s),E(ce.$$.fragment,s),Ie=f(s),Ne=c(s,"P",{});var wr=u(Ne);ja=r(wr,"\u7B2C\u4E00\u6B65\u662F\u5BF9\u6570\u636E\u8FDB\u884C\u6807\u8BB0\uFF0C\u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u5C06\u5176\u7528\u4E8E\u8BAD\u7EC3\u3002\u7531\u4E8E\u6211\u4EEC\u7684\u76EE\u6807\u4E3B\u8981\u662F\u81EA\u52A8\u5B8C\u6210\u77ED\u51FD\u6570\u8C03\u7528\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u4FDD\u6301\u4E0A\u4E0B\u6587\u5927\u5C0F\u76F8\u5BF9\u8F83\u5C0F\u3002\u8FD9\u6837\u505A\u7684\u597D\u5904\u662F\u6211\u4EEC\u53EF\u4EE5\u66F4\u5FEB\u5730\u8BAD\u7EC3\u6A21\u578B\u5E76\u4E14\u5B83\u9700\u8981\u7684\u5185\u5B58\u663E\u7740\u51CF\u5C11\u3002\u5982\u679C\u60A8\u7684\u5E94\u7528\u7A0B\u5E8F\u62E5\u6709\u66F4\u591A\u4E0A\u4E0B\u6587\u5F88\u91CD\u8981\uFF08\u4F8B\u5982\uFF0C\u5982\u679C\u60A8\u5E0C\u671B\u6A21\u578B\u57FA\u4E8E\u5177\u6709\u51FD\u6570\u5B9A\u4E49\u7684\u6587\u4EF6\u7F16\u5199\u5355\u5143\u6D4B\u8BD5\uFF09\uFF0C\u8BF7\u786E\u4FDD\u589E\u52A0\u8BE5\u6570\u91CF\uFF0C\u4F46\u8BF7\u8BB0\u4F4F\uFF0C\u8FD9\u9700\u8981\u66F4\u5927\u7684 GPU \u5185\u5B58\u5360\u7528\u3002\u73B0\u5728\uFF0C\u8BA9\u6211\u4EEC\u5C06\u4E0A\u4E0B\u6587\u5927\u5C0F\u56FA\u5B9A\u4E3A 128 \u4E2A\u6807\u8BB0\uFF0C\u800C\u4E0D\u662F GPT-2 \u6216 GPT-3 \u4E2D\u5206\u522B\u4F7F\u7528\u7684 1,024 \u6216 2,048 \u4E2A\u6807\u8BB0\u3002"),wr.forEach(e),Se=f(s),rs=c(s,"P",{});var aa=u(rs);wa=r(aa,"\u5927\u591A\u6570\u6587\u6863\u5305\u542B\u8D85\u8FC7 128 \u4E2A\u6807\u8BB0\uFF0C\u56E0\u6B64\u7B80\u5355\u5730\u5C06\u8F93\u5165\u622A\u65AD\u5230\u6700\u5927\u957F\u5EA6\u5C06\u6D88\u9664\u6211\u4EEC\u6570\u636E\u96C6\u7684\u5F88\u5927\u4E00\u90E8\u5206\u3002\u76F8\u53CD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 "),ue=c(aa,"CODE",{});var yr=u(ue);ya=r(yr,"return_overflowing_tokens"),yr.forEach(e),va=r(aa," \u6807\u8BB0\u6574\u4E2A\u8F93\u5165\u5E76\u5C06\u5176\u5206\u6210\u51E0\u4E2A\u5757\u7684\u9009\u9879\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728"),me=c(aa,"A",{href:!0});var vr=u(me);fe=r(vr,"\u7B2C\u516D\u7AE0"),vr.forEach(e),Dt=r(aa,". \u6211\u4EEC\u8FD8\u5C06\u4F7F\u7528 "),zs=c(aa,"CODE",{});var qr=u(zs);Ct=r(qr,"return_length"),qr.forEach(e),Re=r(aa," \u9009\u9879\u81EA\u52A8\u8FD4\u56DE\u6BCF\u4E2A\u521B\u5EFA\u7684\u5757\u7684\u957F\u5EA6\u3002\u901A\u5E38\u6700\u540E\u4E00\u4E2A\u5757\u4F1A\u5C0F\u4E8E\u4E0A\u4E0B\u6587\u5927\u5C0F\uFF0C\u6211\u4EEC\u4F1A\u53BB\u6389\u8FD9\u4E9B\u5757\u4EE5\u907F\u514D\u586B\u5145\u95EE\u9898\uFF1B\u56E0\u4E3A\u65E0\u8BBA\u5982\u4F55\u6211\u4EEC\u90FD\u6709\u5927\u91CF\u6570\u636E\u3002"),aa.forEach(e),Ot=f(s),ks=c(s,"DIV",{class:!0});var kn=u(ks);fs=c(kn,"IMG",{class:!0,src:!0,alt:!0}),js=f(kn),de=c(kn,"IMG",{class:!0,src:!0,alt:!0}),kn.forEach(e),Gt=f(s),Be=c(s,"P",{});var Er=u(Be);ut=r(Er,"\u8BA9\u6211\u4EEC\u901A\u8FC7\u67E5\u770B\u524D\u4E24\u4E2A\u793A\u4F8B\u6765\u786E\u5207\u4E86\u89E3\u8FD9\u662F\u5982\u4F55\u5DE5\u4F5C\u7684\uFF1A"),Er.forEach(e),Mt=f(s),E(he.$$.fragment,s),mt=f(s),E(ds.$$.fragment,s),ft=f(s),os=c(s,"P",{});var jn=u(os);Ft=r(jn,"\u6211\u4EEC\u53EF\u4EE5\u770B \u5230\uFF0C\u4ECE\u8FD9\u4E24\u4E2A\u793A\u4F8B\u4E2D\u6211\u4EEC\u603B\u5171\u5F97\u5230\u4E86 34 \u4E2A\u7247\u6BB5\u3002\u67E5\u770B\u5757\u957F\u5EA6\uFF0C\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u4E24\u4E2A\u6587\u6863\u672B\u5C3E\u7684\u5757\u90FD\u5C11\u4E8E 128 \u4E2A\u6807\u8BB0\uFF08\u5206\u522B\u4E3A 117 \u548C 41\uFF09\u3002\u8FD9\u4E9B\u4EC5\u4EE3\u8868\u6211\u4EEC\u62E5\u6709\u7684\u6570\u636E\u96C6\u7684\u4E00\u5C0F\u90E8\u5206\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u5B89\u5168\u5730\u5C06\u5B83\u4EEC\u6254\u6389\u3002\u901A\u8FC7 "),ws=c(jn,"CODE",{});var xr=u(ws);Ea=r(xr,"overflow_to_sample_mapping"),xr.forEach(e),dt=r(jn," \u5B57\u6BB5\uFF0C\u6211\u4EEC\u8FD8\u53EF\u4EE5\u91CD\u5EFA\u54EA\u4E9B\u5757\u5C5E\u4E8E\u54EA\u4E9B\u8F93\u5165\u6837\u672C\u3002"),jn.forEach(e),Lt=f(s),ps=c(s,"P",{});var la=u(ps);Ht=r(la,"\u901A\u8FC7\u8FD9\u4E2A\u64CD\u4F5C\uFF0C\u6211\u4EEC\u4F7F\u7528\u4E86\u4E00\u4E2A\u65B9\u4FBF\u7684\u{1F917} Datasets \u4E2D\u7684"),Ps=c(la,"CODE",{});var zr=u(Ps);It=r(zr,"Dataset.map()"),zr.forEach(e),Ue=r(la," \u51FD\u6570\uFF0C\u5C31\u662F\u4E0D\u9700\u8981\u4E00\u5BF9\u4E00\u7684\u6620\u5C04\uFF1B\u6B63\u5982\u6211\u4EEC\u5728"),We=c(la,"A",{href:!0});var Pr=u(We);Nt=r(Pr,"\u7B2C\u4E09\u8282"),Pr.forEach(e),$e=r(la,",\u6211\u4EEC\u53EF\u4EE5\u521B\u5EFA\u5177\u6709\u6BD4\u8F93\u5165\u6279\u6B21\u66F4\u591A\u6216\u66F4\u5C11\u5143\u7D20\u7684\u6279\u6B21\u3002\u8FD9\u5728\u6267\u884C\u66F4\u6539\u5143\u7D20\u6570\u91CF\u7684\u6570\u636E\u589E\u5F3A\u6216\u6570\u636E\u8FC7\u6EE4\u7B49\u64CD\u4F5C\u65F6\u975E\u5E38\u6709\u7528\u3002\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\uFF0C\u5F53\u5C06\u6BCF\u4E2A\u5143\u7D20\u6807\u8BB0\u4E3A\u6307\u5B9A\u4E0A\u4E0B\u6587\u5927\u5C0F\u7684\u5757\u65F6\uFF0C\u6211\u4EEC\u4ECE\u6BCF\u4E2A\u6587\u6863\u4E2D\u521B\u5EFA\u4E86\u8BB8\u591A\u6837\u672C\u3002\u6211\u4EEC\u53EA\u9700\u8981\u786E\u4FDD\u5220\u9664\u73B0\u6709\u7684\u5217\uFF0C\u56E0\u4E3A\u5B83\u4EEC\u7684\u5927\u5C0F\u5B58\u5728\u51B2\u7A81\u3002\u5982\u679C\u6211\u4EEC\u60F3\u4FDD\u7559\u5B83\u4EEC\uFF0C\u6211\u4EEC\u53EF\u4EE5\u9002\u5F53\u5730\u91CD\u590D\u5B83\u4EEC\uFF0C\u5E76\u5728"),Xe=c(la,"CODE",{});var Tr=u(Xe);be=r(Tr,"Dataset.map()"),Tr.forEach(e),St=r(la," \u8C03\u7528\u4E2D\u8FD4\u56DE\u5B83\u4EEC:"),la.forEach(e),a=f(s),E(k.$$.fragment,s),xa=f(s),E(Ke.$$.fragment,s),za=f(s),ge=c(s,"P",{});var Dr=u(ge);Qa=r(Dr,"\u6211\u4EEC\u73B0\u5728\u6709 1670 \u4E07\u4E2A\u793A\u4F8B\uFF0C\u6BCF\u4E2A\u793A\u4F8B\u6709 128 \u4E2Atokens \uFF0C\u603B\u5171\u76F8\u5F53\u4E8E\u5927\u7EA6 21 \u4EBF\u4E2Atokens \u3002\u4F5C\u4E3A\u53C2\u8003\uFF0COpenAI \u7684 GPT-3 \u548C Codex \u6A21\u578B\u5206\u522B\u5728 300 \u548C 1000 \u4EBF\u4E2Atokens \u4E0A\u8BAD\u7EC3\uFF0C\u5176\u4E2D Codex \u6A21\u578B\u4ECE GPT-3 \u68C0\u67E5\u70B9\u521D\u59CB\u5316\u3002\u6211\u4EEC\u5728\u672C\u8282\u4E2D\u7684\u76EE\u6807\u4E0D\u662F\u4E0E\u8FD9\u4E9B\u6A21\u578B\u7ADE\u4E89\uFF0C\u8FD9\u4E9B\u6A21\u578B\u53EF\u4EE5\u751F\u6210\u957F\u800C\u8FDE\u8D2F\u7684\u6587\u672C\uFF0C\u800C\u662F\u521B\u5EFA\u4E00\u4E2A\u7F29\u5C0F\u7248\u672C\uFF0C\u4E3A\u6570\u636E\u79D1\u5B66\u5BB6\u63D0\u4F9B\u5FEB\u901F\u81EA\u52A8\u5B8C\u6210\u529F\u80FD\u3002"),Dr.forEach(e),X=f(s),ht=c(s,"P",{});var Cr=u(ht);sl=r(Cr,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u4E86\u6570\u636E\u96C6\uFF0C\u8BA9\u6211\u4EEC\u8BBE\u7F6E\u6A21\u578B\uFF01"),Cr.forEach(e),Pa=f(s),E(ke.$$.fragment,s),Ta=f(s),Ve=c(s,"H2",{id:!0});var Or=u(Ve);el=r(Or,"\u521D\u59CB\u5316\u65B0\u6A21\u578B"),Or.forEach(e),Da=f(s),Ts=c(s,"P",{});var zl=u(Ts);tl=r(zl,"\u6211\u4EEC\u7684\u7B2C\u4E00\u6B65\u662F\u65B0\u521D\u59CB\u5316\u4E00\u4E2A GPT-2 \u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5BF9\u6211\u4EEC\u7684\u6A21\u578B\u4F7F\u7528\u4E0E\u5C0F\u578B GPT-2 \u6A21\u578B\u76F8\u540C\u7684\u914D\u7F6E\uFF0C\u56E0\u6B64\u6211\u4EEC\u52A0\u8F7D\u9884\u8BAD\u7EC3\u914D\u7F6E\uFF0C\u786E\u4FDD\u5206\u8BCD\u5668\u5927\u5C0F\u4E0E\u6A21\u578B\u8BCD\u6C47\u91CF\u5927\u5C0F\u5339\u914D\u5E76\u8BBE\u7F6E "),Zs=c(zl,"CODE",{});var Ar=u(Zs);al=r(Ar,"bos"),Ar.forEach(e),ll=r(zl," \u548C "),Rt=c(zl,"CODE",{});var Gr=u(Rt);Ye=r(Gr,"eos"),Gr.forEach(e),nl=r(zl," \uFF08\u5E8F\u5217\u7684\u5F00\u59CB\u548C\u7ED3\u675F\uFF09\u4EE4\u724C ID\uFF1A"),zl.forEach(e),Ca=f(s),vs.l(s),Ds=f(s),Cs=c(s,"P",{});var Pl=u(Cs);rl=r(Pl,"\u6211\u4EEC\u7684\u6A21\u578B\u6709 1.24 \u4EBF\u4E2A\u53C2\u6570\uFF0C\u6211\u4EEC\u5FC5\u987B\u5BF9\u5176\u8FDB\u884C\u8C03\u6574\u3002\u5728\u5F00\u59CB\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u8D1F\u8D23\u521B\u5EFA\u6279\u6B21\u7684\u6570\u636E\u6574\u7406\u5668\u3002\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528 "),Bt=c(Pl,"CODE",{});var Mr=u(Bt);ol=r(Mr,"DataCollatorForLanguageModeling"),Mr.forEach(e),Ze=r(Pl," \uFF0C\u5B83\u662F\u4E13\u4E3A\u8BED\u8A00\u5EFA\u6A21\u800C\u8BBE\u8BA1\uFF08\u987E\u540D\u601D\u4E49\uFF09\u3002\u9664\u4E86\u5806\u53E0\u548C\u586B\u5145\u6279\u6B21\uFF0C\u5B83\u8FD8\u8D1F\u8D23\u521B\u5EFA\u8BED\u8A00\u6A21\u578B\u6807\u7B7E\u2014\u2014\u5728\u56E0\u679C\u8BED\u8A00\u5EFA\u6A21\u4E2D\uFF0C\u8F93\u5165\u4E5F\u7528\u4F5C\u6807\u7B7E\uFF08\u53EA\u662F\u79FB\u52A8\u4E86\u4E00\u4E2A\u5143\u7D20\uFF09\uFF0C\u5E76\u4E14\u8FD9\u4E2A\u6570\u636E\u6574\u7406\u5668\u5728\u8BAD\u7EC3\u671F\u95F4\u5373\u65F6\u521B\u5EFA\u5B83\u4EEC\uFF0C\u6240\u4EE5\u6211\u4EEC\u4E0D\u9700\u8981\u590D\u5236 "),Ut=c(Pl,"CODE",{});var Fr=u(Ut);pl=r(Fr,"input_ids"),Fr.forEach(e),Js=r(Pl,"\u3002"),Pl.forEach(e),Oa=f(s),Os=c(s,"P",{});var Tl=u(Os);il=r(Tl,"\u6CE8\u610F "),Wt=c(Tl,"CODE",{});var Lr=u(Wt);Je=r(Lr,"DataCollatorForLanguageModeling"),Lr.forEach(e),_l=r(Tl," \u652F\u6301\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21 (MLM) \u548C\u56E0\u679C\u8BED\u8A00\u5EFA\u6A21 (CLM)\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B\u5B83\u4E3A MLM \u51C6\u5907\u6570\u636E\uFF0C\u4F46\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8BBE\u7F6E"),Xt=c(Tl,"CODE",{});var Hr=u(Xt);Kt=r(Hr,"mlm=False"),Hr.forEach(e),cl=r(Tl,"\u53C2\u6570\u5207\u6362\u5230 CLM \uFF1A"),Tl.forEach(e),Aa=f(s),we.l(s),ul=f(s),ml=c(s,"P",{});var Ir=u(ml);En=r(Ir,"\u8BA9\u6211\u4EEC\u770B\u4E00\u4E2A\u4F8B\u5B50\uFF1A"),Ir.forEach(e),Bl=f(s),E(Ga.$$.fragment,s),Ul=f(s),ve.l(s),fl=f(s),dl=c(s,"P",{});var Nr=u(dl);xn=r(Nr,"\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u793A\u4F8B\u5DF2\u7ECF\u5806\u53E0\u5728\u4E00\u8D77\uFF0C\u5E76\u4E14\u6240\u6709\u5F20\u91CF\u90FD\u5177\u6709\u76F8\u540C\u7684\u5F62\u72B6\u3002"),Nr.forEach(e),Wl=f(s),Q&&Q.l(s),hl=f(s),E(Vt.$$.fragment,s),Xl=f(s),$l=c(s,"P",{});var Sr=u($l);zn=r(Sr,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u51C6\u5907\u597D\u5B9E\u9645\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u7684\u4E00\u5207\u4E86\u2014\u2014\u6BD5\u7ADF\u8FD9\u4E0D\u662F\u90A3\u4E48\u591A\u5DE5\u4F5C\uFF01\u5728\u6211\u4EEC\u5F00\u59CB\u8BAD\u7EC3\u4E4B\u524D\uFF0C\u6211\u4EEC\u5E94\u8BE5\u767B\u5F55 Hugging Face\u3002\u5982\u679C\u60A8\u5728\u7B14\u8BB0\u672C\u4E0A\u5DE5\u4F5C\uFF0C\u5219\u53EF\u4EE5\u4F7F\u7528\u4EE5\u4E0B\u5B9E\u7528\u7A0B\u5E8F\u529F\u80FD\uFF1A"),Sr.forEach(e),Kl=f(s),E(Ma.$$.fragment,s),Vl=f(s),bl=c(s,"P",{});var Rr=u(bl);Pn=r(Rr,"\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u767B\u5F55\u51ED\u636E\u3002"),Rr.forEach(e),Yl=f(s),gl=c(s,"P",{});var Br=u(gl);Tn=r(Br,"\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),Br.forEach(e),Zl=f(s),E(Fa.$$.fragment,s),Jl=f(s),Ee.l(s),kl=f(s),E(Yt.$$.fragment,s),Ql=f(s),E(Zt.$$.fragment,s),sn=f(s),La=c(s,"H2",{id:!0});var Ur=u(La);Dn=r(Ur,"\u4F7F\u7528\u7BA1\u9053\u751F\u6210\u4EE3\u7801"),Ur.forEach(e),en=f(s),Jt=c(s,"P",{});var wn=u(Jt);Cn=r(wn,"\u73B0\u5728\u662F\u5173\u952E\u7684\u90E8\u5206\uFF1A\u8BA9\u6211\u4EEC\u770B\u770B\u7ECF\u8FC7\u8BAD\u7EC3\u7684\u6A21\u578B\u7684\u5B9E\u9645\u6548\u679C\u5982\u4F55\uFF01\u6211\u4EEC\u53EF\u4EE5\u5728\u65E5\u5FD7\u4E2D\u770B\u5230\u635F\u5931\u7A33\u6B65\u4E0B\u964D\uFF0C\u4F46\u4E3A\u4E86\u8BA9\u6A21\u578B\u8FDB\u884C\u6D4B\u8BD5\uFF0C\u8BA9\u6211\u4EEC\u770B\u770B\u5B83\u5728\u67D0\u4E9B\u6D4B\u8BD5\u4E0A\u7684\u8868\u73B0\u5982\u4F55\u3002\u4E3A\u6B64\uFF0C\u6211\u4EEC\u5C06\u6A21\u578B\u5305\u88C5\u5728\u6587\u672C\u751F\u6210\u4E2D\u7684"),Ol=c(wn,"CODE",{});var Wr=u(Ol);On=r(Wr,"pipeline"),Wr.forEach(e),An=r(wn," \uFF0C\u5982\u679C\u6709\u53EF\u7528\u7684\uFF0C\u6211\u4EEC\u4F1A\u5C06\u5B83\u653E\u5728 GPU \u4E0A\u8FDB\u884C\u5FEB\u901F\u751F\u6210\uFF1A"),wn.forEach(e),tn=f(s),ze.l(s),jl=f(s),wl=c(s,"P",{});var Xr=u(wl);Gn=r(Xr,"\u8BA9\u6211\u4EEC\u4ECE\u521B\u5EFA\u6563\u70B9\u56FE\u7684\u7B80\u5355\u4EFB\u52A1\u5F00\u59CB\uFF1A"),Xr.forEach(e),an=f(s),E(Ha.$$.fragment,s),ln=f(s),E(Ia.$$.fragment,s),nn=f(s),Qe=c(s,"P",{});var Dl=u(Qe);Mn=r(Dl,"\u7ED3\u679C\u770B\u8D77\u6765\u662F\u6B63\u786E\u7684\u3002\u5B83\u4E5F\u9002\u7528\u4E8E "),Al=c(Dl,"CODE",{});var Kr=u(Al);Fn=r(Kr,"pandas"),Kr.forEach(e),Ln=r(Dl," \u7C7B\u578B\uFF1F\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u4F7F\u7528\u4E24\u4E2A\u6570\u7EC4\u53EF\u4EE5\u521B\u5EFA\u4E00\u4E2A "),Gl=c(Dl,"CODE",{});var Vr=u(Gl);Hn=r(Vr,"DataFrame"),Vr.forEach(e),In=r(Dl," \uFF1A"),Dl.forEach(e),rn=f(s),E(Na.$$.fragment,s),on=f(s),E(Sa.$$.fragment,s),pn=f(s),st=c(s,"P",{});var Cl=u(st);Nn=r(Cl,"\u5F88\u597D\uFF0C\u8FD9\u662F\u6B63\u786E\u7684\u7B54\u6848\u2014\u2014\u5C3D\u7BA1\u5B83\u968F\u540E\u518D\u6B21\u63D2\u5165\u4E86\u5217 "),Ml=c(Cl,"CODE",{});var Yr=u(Ml);Sn=r(Yr,"x"),Yr.forEach(e),Rn=r(Cl," \u3002\u7531\u4E8E\u751F\u6210\u7684token\u6570\u91CF\u6709\u9650\uFF0C\u4EE5\u4E0B "),Fl=c(Cl,"CODE",{});var Zr=u(Fl);Bn=r(Zr,"for"),Zr.forEach(e),Un=r(Cl," \u5FAA\u73AF\u88AB\u5207\u65AD\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u53EF\u4EE5\u505A\u4E00\u4E9B\u66F4\u590D\u6742\u7684\u4E8B\u60C5\u5E76\u8BA9\u6A21\u578B\u5E2E\u52A9\u6211\u4EEC\u5206\u7EC4\u64CD\u4F5C\uFF1A"),Cl.forEach(e),_n=f(s),E(Ra.$$.fragment,s),cn=f(s),E(Ba.$$.fragment,s),un=f(s),Qt=c(s,"P",{});var yn=u(Qt);Wn=r(yn,"\u4E0D\u9519;\u8FD9\u662F\u6B63\u786E\u7684\u505A\u6CD5\u3002\u6700\u540E\uFF0C\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u662F\u5426\u4E5F\u53EF\u4EE5\u5C06\u5176\u7528\u4E8E "),Ll=c(yn,"CODE",{});var Jr=u(Ll);Xn=r(Jr,"scikit-learn"),Jr.forEach(e),Kn=r(yn," \u5E76\u5EFA\u7ACB\u4E00\u4E2A\u968F\u673A\u68EE\u6797\u6A21\u578B\uFF1A"),yn.forEach(e),mn=f(s),E(Ua.$$.fragment,s),fn=f(s),E(Wa.$$.fragment,s),dn=f(s),$t.l(s),yl=f(s),ss&&ss.l(s),vl=qn(),this.h()},h(){H(l,"name","hf:doc:metadata"),H(l,"content",JSON.stringify(Go)),H(y,"id",""),H($,"href","/course/chapter1"),H(De,"href","/course/chapter6"),vn(ts.src,Ce="https://hf.space/gradioiframe/course-demos/codeparrot-ds/+")||H(ts,"src",Ce),H(ts,"frameborder","0"),H(ts,"height","300"),H(ts,"title","Gradio app"),H(ts,"class","block dark:hidden container p-0 flex-grow space-iframe"),H(ts,"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"),H(ts,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),vn(V.src,_a="https://hf.space/gradioiframe/course-demos/codeparrot-ds-darkmode/+")||H(V,"src",_a),H(V,"frameborder","0"),H(V,"height","300"),H(V,"title","Gradio app"),H(V,"class","hidden dark:block container p-0 flex-grow space-iframe"),H(V,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),H(V,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),H(_s,"href","https://huggingface.co/huggingface-course/codeparrot-ds?text=plt.imshow%28"),H(_s,"rel","nofollow"),H(Ms,"id",""),H(xs,"href","https://learning.oreilly.com/library/view/natural-language-processing/9781098103231/"),H(xs,"rel","nofollow"),H(as,"href","https://huggingface.co/datasets/transformersbook/codeparrot"),H(as,"rel","nofollow"),H(ms,"id",""),H(me,"href","/course/chapter6/4"),H(fs,"class","block dark:hidden"),vn(fs.src,qa="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/chunking_texts.svg")||H(fs,"src",qa),H(fs,"alt","Chunking a large texts in several pieces."),H(de,"class","hidden dark:block"),vn(de.src,At="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/chunking_texts-dark.svg")||H(de,"src",At),H(de,"alt","Chunking a large texts in several pieces."),H(ks,"class","flex justify-center"),H(We,"href","/course/chapter7/3"),H(Ve,"id",""),H(La,"id","")},m(s,i){t(document.head,l),o(s,d,i),x(p,s,i),o(s,h,i),o(s,y,i),t(y,j),o(s,v,i),Xa[P].m(s,i),o(s,D,i),o(s,G,i),t(G,L),t(G,$),t($,M),t(G,I),o(s,R,i),o(s,A,i),t(A,B),t(A,W),t(W,F),t(A,N),t(A,S),t(S,Y),t(A,Z),t(A,K),t(K,es),t(A,is),t(A,C),t(C,U),t(A,Pe),o(s,qs,i),x(hs,s,i),o(s,Es,i),o(s,J,i),t(J,Te),t(J,De),t(De,tt),t(J,pa),t(J,at),t(at,lt),t(J,ia),o(s,bt,i),o(s,ts,i),o(s,nt,i),o(s,V,i),o(s,Qs,i),o(s,Gs,i),t(Gs,gt),t(Gs,_s),t(_s,kt),t(Gs,Oe),o(s,jt,i),o(s,Ms,i),t(Ms,$s),o(s,Ae,i),o(s,ns,i),t(ns,ca),t(ns,xs),t(xs,ua),t(ns,ma),t(ns,se),t(se,fa),t(ns,wt),t(ns,as),t(as,da),t(ns,rt),o(s,yt,i),o(s,Fs,i),t(Fs,ot),t(Fs,pt),t(pt,ha),t(Fs,vt),o(s,Ls,i),x(Hs,s,i),o(s,ee,i),o(s,Ge,i),t(Ge,qt),o(s,Is,i),x(Ns,s,i),o(s,te,i),x(ae,s,i),o(s,it,i),o(s,bs,i),t(bs,Et),o(s,cs,i),x(le,s,i),o(s,Me,i),o(s,Fe,i),t(Fe,$a),o(s,ne,i),x(re,s,i),o(s,xt,i),x(Ss,s,i),o(s,Rs,i),o(s,oe,i),t(oe,Le),o(s,zt,i),x(Bs,s,i),o(s,Us,i),x(Ws,s,i),o(s,pe,i),x(Xs,s,i),o(s,_t,i),o(s,gs,i),t(gs,Pt),o(s,Ks,i),x(Vs,s,i),o(s,us,i),x(ie,s,i),o(s,He,i),o(s,Ys,i),t(Ys,ba),t(Ys,_e),t(_e,ga),t(Ys,ka),o(s,ct,i),o(s,ms,i),t(ms,Tt),o(s,ls,i),x(ce,s,i),o(s,Ie,i),o(s,Ne,i),t(Ne,ja),o(s,Se,i),o(s,rs,i),t(rs,wa),t(rs,ue),t(ue,ya),t(rs,va),t(rs,me),t(me,fe),t(rs,Dt),t(rs,zs),t(zs,Ct),t(rs,Re),o(s,Ot,i),o(s,ks,i),t(ks,fs),t(ks,js),t(ks,de),o(s,Gt,i),o(s,Be,i),t(Be,ut),o(s,Mt,i),x(he,s,i),o(s,mt,i),x(ds,s,i),o(s,ft,i),o(s,os,i),t(os,Ft),t(os,ws),t(ws,Ea),t(os,dt),o(s,Lt,i),o(s,ps,i),t(ps,Ht),t(ps,Ps),t(Ps,It),t(ps,Ue),t(ps,We),t(We,Nt),t(ps,$e),t(ps,Xe),t(Xe,be),t(ps,St),o(s,a,i),x(k,s,i),o(s,xa,i),x(Ke,s,i),o(s,za,i),o(s,ge,i),t(ge,Qa),o(s,X,i),o(s,ht,i),t(ht,sl),o(s,Pa,i),x(ke,s,i),o(s,Ta,i),o(s,Ve,i),t(Ve,el),o(s,Da,i),o(s,Ts,i),t(Ts,tl),t(Ts,Zs),t(Zs,al),t(Ts,ll),t(Ts,Rt),t(Rt,Ye),t(Ts,nl),o(s,Ca,i),Ka[ys].m(s,i),o(s,Ds,i),o(s,Cs,i),t(Cs,rl),t(Cs,Bt),t(Bt,ol),t(Cs,Ze),t(Cs,Ut),t(Ut,pl),t(Cs,Js),o(s,Oa,i),o(s,Os,i),t(Os,il),t(Os,Wt),t(Wt,Je),t(Os,_l),t(Os,Xt),t(Xt,Kt),t(Os,cl),o(s,Aa,i),Va[je].m(s,i),o(s,ul,i),o(s,ml,i),t(ml,En),o(s,Bl,i),x(Ga,s,i),o(s,Ul,i),Ya[ye].m(s,i),o(s,fl,i),o(s,dl,i),t(dl,xn),o(s,Wl,i),Q&&Q.m(s,i),o(s,hl,i),x(Vt,s,i),o(s,Xl,i),o(s,$l,i),t($l,zn),o(s,Kl,i),x(Ma,s,i),o(s,Vl,i),o(s,bl,i),t(bl,Pn),o(s,Yl,i),o(s,gl,i),t(gl,Tn),o(s,Zl,i),x(Fa,s,i),o(s,Jl,i),Za[qe].m(s,i),o(s,kl,i),x(Yt,s,i),o(s,Ql,i),x(Zt,s,i),o(s,sn,i),o(s,La,i),t(La,Dn),o(s,en,i),o(s,Jt,i),t(Jt,Cn),t(Jt,Ol),t(Ol,On),t(Jt,An),o(s,tn,i),Ja[xe].m(s,i),o(s,jl,i),o(s,wl,i),t(wl,Gn),o(s,an,i),x(Ha,s,i),o(s,ln,i),x(Ia,s,i),o(s,nn,i),o(s,Qe,i),t(Qe,Mn),t(Qe,Al),t(Al,Fn),t(Qe,Ln),t(Qe,Gl),t(Gl,Hn),t(Qe,In),o(s,rn,i),x(Na,s,i),o(s,on,i),x(Sa,s,i),o(s,pn,i),o(s,st,i),t(st,Nn),t(st,Ml),t(Ml,Sn),t(st,Rn),t(st,Fl),t(Fl,Bn),t(st,Un),o(s,_n,i),x(Ra,s,i),o(s,cn,i),x(Ba,s,i),o(s,un,i),o(s,Qt,i),t(Qt,Wn),t(Qt,Ll),t(Ll,Xn),t(Qt,Kn),o(s,mn,i),x(Ua,s,i),o(s,fn,i),x(Wa,s,i),o(s,dn,i),$t.m(s,i),o(s,yl,i),ss&&ss.m(s,i),o(s,vl,i),hn=!0},p(s,[i]){const Hl={};i&1&&(Hl.fw=s[0]),p.$set(Hl);let sa=P;P=Zn(s),P!==sa&&(ra(),g(Xa[sa],1,1,()=>{Xa[sa]=null}),na(),w=Xa[P],w||(w=Xa[P]=Yn[P](s),w.c()),b(w,1),w.m(D.parentNode,D));const Il={};i&2&&(Il.$$scope={dirty:i,ctx:s}),Xs.$set(Il);const As={};i&2&&(As.$$scope={dirty:i,ctx:s}),ke.$set(As);let ql=ys;ys=Qn(s),ys!==ql&&(ra(),g(Ka[ql],1,1,()=>{Ka[ql]=null}),na(),vs=Ka[ys],vs||(vs=Ka[ys]=Jn[ys](s),vs.c()),b(vs,1),vs.m(Ds.parentNode,Ds));let El=je;je=er(s),je!==El&&(ra(),g(Va[El],1,1,()=>{Va[El]=null}),na(),we=Va[je],we||(we=Va[je]=sr[je](s),we.c()),b(we,1),we.m(ul.parentNode,ul));let xl=ye;ye=ar(s),ye!==xl&&(ra(),g(Ya[xl],1,1,()=>{Ya[xl]=null}),na(),ve=Ya[ye],ve||(ve=Ya[ye]=tr[ye](s),ve.c()),b(ve,1),ve.m(fl.parentNode,fl)),s[0]==="tf"?Q?i&1&&b(Q,1):(Q=Qr(),Q.c(),b(Q,1),Q.m(hl.parentNode,hl)):Q&&(ra(),g(Q,1,1,()=>{Q=null}),na());const Nl={};i&2&&(Nl.$$scope={dirty:i,ctx:s}),Vt.$set(Nl);let et=qe;qe=nr(s),qe!==et&&(ra(),g(Za[et],1,1,()=>{Za[et]=null}),na(),Ee=Za[qe],Ee||(Ee=Za[qe]=lr[qe](s),Ee.c()),b(Ee,1),Ee.m(kl.parentNode,kl));const Sl={};i&2&&(Sl.$$scope={dirty:i,ctx:s}),Yt.$set(Sl);const Rl={};i&3&&(Rl.$$scope={dirty:i,ctx:s}),Zt.$set(Rl);let ea=xe;xe=or(s),xe!==ea&&(ra(),g(Ja[ea],1,1,()=>{Ja[ea]=null}),na(),ze=Ja[xe],ze||(ze=Ja[xe]=rr[xe](s),ze.c()),b(ze,1),ze.m(jl.parentNode,jl)),$n!==($n=pr(s))&&($t.d(1),$t=$n(s),$t&&($t.c(),$t.m(yl.parentNode,yl))),s[0]==="pt"?ss?i&1&&b(ss,1):(ss=so(s),ss.c(),b(ss,1),ss.m(vl.parentNode,vl)):ss&&(ra(),g(ss,1,1,()=>{ss=null}),na())},i(s){hn||(b(p.$$.fragment,s),b(w),b(hs.$$.fragment,s),b(Hs.$$.fragment,s),b(Ns.$$.fragment,s),b(ae.$$.fragment,s),b(le.$$.fragment,s),b(re.$$.fragment,s),b(Ss.$$.fragment,s),b(Bs.$$.fragment,s),b(Ws.$$.fragment,s),b(Xs.$$.fragment,s),b(Vs.$$.fragment,s),b(ie.$$.fragment,s),b(ce.$$.fragment,s),b(he.$$.fragment,s),b(ds.$$.fragment,s),b(k.$$.fragment,s),b(Ke.$$.fragment,s),b(ke.$$.fragment,s),b(vs),b(we),b(Ga.$$.fragment,s),b(ve),b(Q),b(Vt.$$.fragment,s),b(Ma.$$.fragment,s),b(Fa.$$.fragment,s),b(Ee),b(Yt.$$.fragment,s),b(Zt.$$.fragment,s),b(ze),b(Ha.$$.fragment,s),b(Ia.$$.fragment,s),b(Na.$$.fragment,s),b(Sa.$$.fragment,s),b(Ra.$$.fragment,s),b(Ba.$$.fragment,s),b(Ua.$$.fragment,s),b(Wa.$$.fragment,s),b(ss),hn=!0)},o(s){g(p.$$.fragment,s),g(w),g(hs.$$.fragment,s),g(Hs.$$.fragment,s),g(Ns.$$.fragment,s),g(ae.$$.fragment,s),g(le.$$.fragment,s),g(re.$$.fragment,s),g(Ss.$$.fragment,s),g(Bs.$$.fragment,s),g(Ws.$$.fragment,s),g(Xs.$$.fragment,s),g(Vs.$$.fragment,s),g(ie.$$.fragment,s),g(ce.$$.fragment,s),g(he.$$.fragment,s),g(ds.$$.fragment,s),g(k.$$.fragment,s),g(Ke.$$.fragment,s),g(ke.$$.fragment,s),g(vs),g(we),g(Ga.$$.fragment,s),g(ve),g(Q),g(Vt.$$.fragment,s),g(Ma.$$.fragment,s),g(Fa.$$.fragment,s),g(Ee),g(Yt.$$.fragment,s),g(Zt.$$.fragment,s),g(ze),g(Ha.$$.fragment,s),g(Ia.$$.fragment,s),g(Na.$$.fragment,s),g(Sa.$$.fragment,s),g(Ra.$$.fragment,s),g(Ba.$$.fragment,s),g(Ua.$$.fragment,s),g(Wa.$$.fragment,s),g(ss),hn=!1},d(s){e(l),s&&e(d),z(p,s),s&&e(h),s&&e(y),s&&e(v),Xa[P].d(s),s&&e(D),s&&e(G),s&&e(R),s&&e(A),s&&e(qs),z(hs,s),s&&e(Es),s&&e(J),s&&e(bt),s&&e(ts),s&&e(nt),s&&e(V),s&&e(Qs),s&&e(Gs),s&&e(jt),s&&e(Ms),s&&e(Ae),s&&e(ns),s&&e(yt),s&&e(Fs),s&&e(Ls),z(Hs,s),s&&e(ee),s&&e(Ge),s&&e(Is),z(Ns,s),s&&e(te),z(ae,s),s&&e(it),s&&e(bs),s&&e(cs),z(le,s),s&&e(Me),s&&e(Fe),s&&e(ne),z(re,s),s&&e(xt),z(Ss,s),s&&e(Rs),s&&e(oe),s&&e(zt),z(Bs,s),s&&e(Us),z(Ws,s),s&&e(pe),z(Xs,s),s&&e(_t),s&&e(gs),s&&e(Ks),z(Vs,s),s&&e(us),z(ie,s),s&&e(He),s&&e(Ys),s&&e(ct),s&&e(ms),s&&e(ls),z(ce,s),s&&e(Ie),s&&e(Ne),s&&e(Se),s&&e(rs),s&&e(Ot),s&&e(ks),s&&e(Gt),s&&e(Be),s&&e(Mt),z(he,s),s&&e(mt),z(ds,s),s&&e(ft),s&&e(os),s&&e(Lt),s&&e(ps),s&&e(a),z(k,s),s&&e(xa),z(Ke,s),s&&e(za),s&&e(ge),s&&e(X),s&&e(ht),s&&e(Pa),z(ke,s),s&&e(Ta),s&&e(Ve),s&&e(Da),s&&e(Ts),s&&e(Ca),Ka[ys].d(s),s&&e(Ds),s&&e(Cs),s&&e(Oa),s&&e(Os),s&&e(Aa),Va[je].d(s),s&&e(ul),s&&e(ml),s&&e(Bl),z(Ga,s),s&&e(Ul),Ya[ye].d(s),s&&e(fl),s&&e(dl),s&&e(Wl),Q&&Q.d(s),s&&e(hl),z(Vt,s),s&&e(Xl),s&&e($l),s&&e(Kl),z(Ma,s),s&&e(Vl),s&&e(bl),s&&e(Yl),s&&e(gl),s&&e(Zl),z(Fa,s),s&&e(Jl),Za[qe].d(s),s&&e(kl),z(Yt,s),s&&e(Ql),z(Zt,s),s&&e(sn),s&&e(La),s&&e(en),s&&e(Jt),s&&e(tn),Ja[xe].d(s),s&&e(jl),s&&e(wl),s&&e(an),z(Ha,s),s&&e(ln),z(Ia,s),s&&e(nn),s&&e(Qe),s&&e(rn),z(Na,s),s&&e(on),z(Sa,s),s&&e(pn),s&&e(st),s&&e(_n),z(Ra,s),s&&e(cn),z(Ba,s),s&&e(un),s&&e(Qt),s&&e(mn),z(Ua,s),s&&e(fn),z(Wa,s),s&&e(dn),$t.d(s),s&&e(yl),ss&&ss.d(s),s&&e(vl)}}}const Go={local:"",sections:[{local:"",title:"\u6536\u96C6\u6570\u636E"},{local:"",title:"\u51C6\u5907\u6570\u636E\u96C6"},{local:"",title:"\u521D\u59CB\u5316\u65B0\u6A21\u578B"},{local:"",title:"\u4F7F\u7528\u7BA1\u9053\u751F\u6210\u4EE3\u7801"},{local:"accelerate",title:"\u7528 \u{1F917} Accelerate \u8BAD\u7EC3"}],title:"\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u56E0\u679C\u8BED\u8A00\u6A21\u578B"};function Mo(O,l,d){let p="pt";return ro(()=>{const h=new URLSearchParams(window.location.search);d(0,p=h.get("fw")||"pt")}),[p]}class Bo extends to{constructor(l){super();ao(this,l,Mo,Ao,lo,{})}}export{Bo as default,Go as metadata};
