import{S as Oc,i as Cc,s as qc,e as o,t,k as f,w,c as p,a as i,h as a,d as s,m,x as E,b as O,g as n,G as l,y as x,q as k,o as g,B as y,M as Tc,N as Ep,p as qr,v as Dc,n as Tr,L as vc}from"../../chunks/vendor-hf-doc-builder.js";import{T as Dr}from"../../chunks/Tip-hf-doc-builder.js";import{Y as wc}from"../../chunks/Youtube-hf-doc-builder.js";import{I as Uo}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as P}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as yc}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Pc}from"../../chunks/FrameworkSwitchCourse-hf-doc-builder.js";function zc(F){let u,j;return u=new yc({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/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section2_tf.ipynb"}]}}),{c(){w(u.$$.fragment)},l(d){E(u.$$.fragment,d)},m(d,$){x(u,d,$),j=!0},i(d){j||(k(u.$$.fragment,d),j=!0)},o(d){g(u.$$.fragment,d),j=!1},d(d){y(u,d)}}}function Ac(F){let u,j;return u=new yc({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/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section2_pt.ipynb"}]}}),{c(){w(u.$$.fragment)},l(d){E(u.$$.fragment,d)},m(d,$){x(u,d,$),j=!0},i(d){j||(k(u.$$.fragment,d),j=!0)},o(d){g(u.$$.fragment,d),j=!1},d(d){y(u,d)}}}function Ic(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u{1F4A1} \u53EA\u8981\u60A8\u7684\u6570\u636E\u96C6\u7531\u5E26\u6709\u76F8\u5E94\u6807\u7B7E\u7684\u5206\u5272\u6210\u5355\u8BCD\u5E76\u7684\u6587\u672C\u7EC4\u6210\uFF0C\u60A8\u5C31\u80FD\u591F\u5C06\u8FD9\u91CC\u63CF\u8FF0\u7684\u6570\u636E\u5904\u7406\u8FC7\u7A0B\u5E94\u7528\u5230\u60A8\u81EA\u5DF1\u7684\u6570\u636E\u96C6\u3002\u5982\u679C\u9700\u8981\u590D\u4E60\u5982\u4F55\u5728.Dataset\u4E2D\u52A0\u8F7D\u81EA\u5B9A\u4E49\u6570\u636E\uFF0C\u8BF7\u53C2\u9605"),d=o("a"),$=t("Chapter 5"),q=t("\u3002"),this.h()},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u{1F4A1} \u53EA\u8981\u60A8\u7684\u6570\u636E\u96C6\u7531\u5E26\u6709\u76F8\u5E94\u6807\u7B7E\u7684\u5206\u5272\u6210\u5355\u8BCD\u5E76\u7684\u6587\u672C\u7EC4\u6210\uFF0C\u60A8\u5C31\u80FD\u591F\u5C06\u8FD9\u91CC\u63CF\u8FF0\u7684\u6570\u636E\u5904\u7406\u8FC7\u7A0B\u5E94\u7528\u5230\u60A8\u81EA\u5DF1\u7684\u6570\u636E\u96C6\u3002\u5982\u679C\u9700\u8981\u590D\u4E60\u5982\u4F55\u5728.Dataset\u4E2D\u52A0\u8F7D\u81EA\u5B9A\u4E49\u6570\u636E\uFF0C\u8BF7\u53C2\u9605"),d=p(b,"A",{href:!0});var T=i(d);$=a(T,"Chapter 5"),T.forEach(s),q=a(b,"\u3002"),b.forEach(s),this.h()},h(){O(d,"href","/course/chapter5")},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Rc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u270F\uFE0F "),d=o("strong"),$=t("\u8F6E\u5230\u4F60\u4E86\uFF01"),q=t(" \u4F7F\u7528 POS \u6216chunking\u6807\u7B7E\u8BC6\u522B\u540C\u4E00\u4E2A\u53E5\u5B50\u3002")},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u270F\uFE0F "),d=p(b,"STRONG",{});var T=i(d);$=a(T,"\u8F6E\u5230\u4F60\u4E86\uFF01"),T.forEach(s),q=a(b," \u4F7F\u7528 POS \u6216chunking\u6807\u7B7E\u8BC6\u522B\u540C\u4E00\u4E2A\u53E5\u5B50\u3002"),b.forEach(s)},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Sc(F){let u,j,d,$,q,v,b,T;return{c(){u=o("p"),j=t("\u270F\uFE0F "),d=o("strong"),$=t("\u8F6E\u5230\u4F60\u4E86\uFF01"),q=t(" \u4E00\u4E9B\u7814\u7A76\u4EBA\u5458\u66F4\u559C\u6B22\u6BCF\u4E2A\u8BCD\u53EA\u5F52\u5C5E\u4E00\u4E2A\u6807\u7B7E, \u5E76\u5206\u914D "),v=o("code"),b=t("-100"),T=t(" \u7ED9\u5B9A\u8BCD\u4E2D\u7684\u5176\u4ED6\u5B50\u6807\u8BB0\u3002\u8FD9\u662F\u4E3A\u4E86\u907F\u514D\u5206\u89E3\u6210\u5927\u91CF\u5B50\u6807\u8BB0\u7684\u957F\u8BCD\u5BF9\u635F\u5931\u9020\u6210\u4E25\u91CD\u5F71\u54CD\u3002\u6309\u7167\u6B64\u89C4\u5219\u66F4\u6539\u524D\u4E00\u4E2A\u51FD\u6570\u4F7F\u6807\u7B7E\u4E0E\u8F93\u5165id\u5BF9\u9F50\u3002")},l(S){u=p(S,"P",{});var R=i(u);j=a(R,"\u270F\uFE0F "),d=p(R,"STRONG",{});var H=i(d);$=a(H,"\u8F6E\u5230\u4F60\u4E86\uFF01"),H.forEach(s),q=a(R," \u4E00\u4E9B\u7814\u7A76\u4EBA\u5458\u66F4\u559C\u6B22\u6BCF\u4E2A\u8BCD\u53EA\u5F52\u5C5E\u4E00\u4E2A\u6807\u7B7E, \u5E76\u5206\u914D "),v=p(R,"CODE",{});var A=i(v);b=a(A,"-100"),A.forEach(s),T=a(R," \u7ED9\u5B9A\u8BCD\u4E2D\u7684\u5176\u4ED6\u5B50\u6807\u8BB0\u3002\u8FD9\u662F\u4E3A\u4E86\u907F\u514D\u5206\u89E3\u6210\u5927\u91CF\u5B50\u6807\u8BB0\u7684\u957F\u8BCD\u5BF9\u635F\u5931\u9020\u6210\u4E25\u91CD\u5F71\u54CD\u3002\u6309\u7167\u6B64\u89C4\u5219\u66F4\u6539\u524D\u4E00\u4E2A\u51FD\u6570\u4F7F\u6807\u7B7E\u4E0E\u8F93\u5165id\u5BF9\u9F50\u3002"),R.forEach(s)},m(S,R){n(S,u,R),l(u,j),l(u,d),l(d,$),l(u,q),l(u,v),l(v,b),l(u,T)},d(S){S&&s(u)}}}function Bc(F){let u,j,d,$,q,v,b,T,S,R,H;return $=new Uo({}),{c(){u=o("h2"),j=o("a"),d=o("span"),w($.$$.fragment),q=f(),v=o("span"),b=t("\u4F7F\u7528 Keras \u5FAE\u8C03\u6A21\u578B"),T=f(),S=o("p"),R=t("\u4F7F\u7528Keras\u7684\u5B9E\u9645\u4EE3\u7801\u5C06\u4E0E\u4E4B\u524D\u975E\u5E38\u76F8\u4F3C;\u552F\u4E00\u7684\u53D8\u5316\u662F\u5C06\u6570\u636E\u6574\u7406\u6210\u6279\u5904\u7406\u7684\u65B9\u5F0F\u548C\u6307\u6807\u8BA1\u7B97\u51FD\u6570\u3002"),this.h()},l(A){u=p(A,"H2",{class:!0});var I=i(u);j=p(I,"A",{id:!0,class:!0,href:!0});var M=i(j);d=p(M,"SPAN",{});var C=i(d);E($.$$.fragment,C),C.forEach(s),M.forEach(s),q=m(I),v=p(I,"SPAN",{});var N=i(v);b=a(N,"\u4F7F\u7528 Keras \u5FAE\u8C03\u6A21\u578B"),N.forEach(s),I.forEach(s),T=m(A),S=p(A,"P",{});var K=i(S);R=a(K,"\u4F7F\u7528Keras\u7684\u5B9E\u9645\u4EE3\u7801\u5C06\u4E0E\u4E4B\u524D\u975E\u5E38\u76F8\u4F3C;\u552F\u4E00\u7684\u53D8\u5316\u662F\u5C06\u6570\u636E\u6574\u7406\u6210\u6279\u5904\u7406\u7684\u65B9\u5F0F\u548C\u6307\u6807\u8BA1\u7B97\u51FD\u6570\u3002"),K.forEach(s),this.h()},h(){O(j,"id","keras"),O(j,"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"),O(j,"href","#keras"),O(u,"class","relative group")},m(A,I){n(A,u,I),l(u,j),l(j,d),x($,d,null),l(u,q),l(u,v),l(v,b),n(A,T,I),n(A,S,I),l(S,R),H=!0},i(A){H||(k($.$$.fragment,A),H=!0)},o(A){g($.$$.fragment,A),H=!1},d(A){A&&s(u),y($),A&&s(T),A&&s(S)}}}function Nc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M;return $=new Uo({}),{c(){u=o("h2"),j=o("a"),d=o("span"),w($.$$.fragment),q=f(),v=o("span"),b=t("\u4F7F\u7528 Trainer API \u5FAE\u8C03\u6A21\u578B"),T=f(),S=o("p"),R=t("\u4F7F\u7528 "),H=o("code"),A=t("Trainer"),I=t(" \u7684\u5B9E\u9645\u4EE3\u7801\u4F1A\u548C\u4EE5\u524D\u4E00\u6837\uFF1B\u552F\u4E00\u7684\u53D8\u5316\u662F\u6570\u636E\u6574\u7406\u6210\u65F6\u6279\u5904\u7406\u7684\u65B9\u5F0F\u548C\u5EA6\u91CF\u8BA1\u7B97\u51FD\u6570\u3002"),this.h()},l(C){u=p(C,"H2",{class:!0});var N=i(u);j=p(N,"A",{id:!0,class:!0,href:!0});var K=i(j);d=p(K,"SPAN",{});var X=i(d);E($.$$.fragment,X),X.forEach(s),K.forEach(s),q=m(N),v=p(N,"SPAN",{});var z=i(v);b=a(z,"\u4F7F\u7528 Trainer API \u5FAE\u8C03\u6A21\u578B"),z.forEach(s),N.forEach(s),T=m(C),S=p(C,"P",{});var W=i(S);R=a(W,"\u4F7F\u7528 "),H=p(W,"CODE",{});var G=i(H);A=a(G,"Trainer"),G.forEach(s),I=a(W," \u7684\u5B9E\u9645\u4EE3\u7801\u4F1A\u548C\u4EE5\u524D\u4E00\u6837\uFF1B\u552F\u4E00\u7684\u53D8\u5316\u662F\u6570\u636E\u6574\u7406\u6210\u65F6\u6279\u5904\u7406\u7684\u65B9\u5F0F\u548C\u5EA6\u91CF\u8BA1\u7B97\u51FD\u6570\u3002"),W.forEach(s),this.h()},h(){O(j,"id","trainer-api"),O(j,"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"),O(j,"href","#trainer-api"),O(u,"class","relative group")},m(C,N){n(C,u,N),l(u,j),l(j,d),x($,d,null),l(u,q),l(u,v),l(v,b),n(C,T,N),n(C,S,N),l(S,R),l(S,H),l(H,A),l(S,I),M=!0},i(C){M||(k($.$$.fragment,C),M=!0)},o(C){g($.$$.fragment,C),M=!1},d(C){C&&s(u),y($),C&&s(T),C&&s(S)}}}function Lc(F){let u,j;return u=new P({props:{code:`from transformers import DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(
    tokenizer=tokenizer, return_tensors="tf"
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(
    tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
)`}}),{c(){w(u.$$.fragment)},l(d){E(u.$$.fragment,d)},m(d,$){x(u,d,$),j=!0},i(d){j||(k(u.$$.fragment,d),j=!0)},o(d){g(u.$$.fragment,d),j=!1},d(d){y(u,d)}}}function Fc(F){let u,j;return u=new P({props:{code:`from transformers import DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer)`}}),{c(){w(u.$$.fragment)},l(d){E(u.$$.fragment,d)},m(d,$){x(u,d,$),j=!0},i(d){j||(k(u.$$.fragment,d),j=!0)},o(d){g(u.$$.fragment,d),j=!1},d(d){y(u,d)}}}function Mc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M;return R=new P({props:{code:`tf_train_dataset = tokenized_datasets["train"].to_tf_dataset(
    columns=["attention_mask", "input_ids", "labels", "token_type_ids"],
    collate_fn=data_collator,
    shuffle=True,
    batch_size=16,
)

tf_eval_dataset = tokenized_datasets["validation"].to_tf_dataset(
    columns=["attention_mask", "input_ids", "labels", "token_type_ids"],
    collate_fn=data_collator,
    shuffle=False,
    batch_size=16,
)`,highlighted:`tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">16</span>,
)

tf_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">16</span>,
)`}}),{c(){u=o("p"),j=t("\u6211\u4EEC\u7684\u6570\u636E\u6574\u7406\u5668\u5DF2\u51C6\u5907\u5C31\u7EEA\uFF01\u73B0\u5728\uFF0C\u8BA9\u6211\u4EEC\u7528\u5B83\u6765\u5236\u4F5C\u4E00\u4E2A\u5E26\u6709"),d=o("code"),$=t("to_tf_dataset()"),q=t("\u65B9\u6CD5\u7684"),v=o("code"),b=t("tf.data.Dataset"),T=t("\u3002"),S=f(),w(R.$$.fragment),H=f(),A=o("p"),I=t("Next stop: the model itself.")},l(C){u=p(C,"P",{});var N=i(u);j=a(N,"\u6211\u4EEC\u7684\u6570\u636E\u6574\u7406\u5668\u5DF2\u51C6\u5907\u5C31\u7EEA\uFF01\u73B0\u5728\uFF0C\u8BA9\u6211\u4EEC\u7528\u5B83\u6765\u5236\u4F5C\u4E00\u4E2A\u5E26\u6709"),d=p(N,"CODE",{});var K=i(d);$=a(K,"to_tf_dataset()"),K.forEach(s),q=a(N,"\u65B9\u6CD5\u7684"),v=p(N,"CODE",{});var X=i(v);b=a(X,"tf.data.Dataset"),X.forEach(s),T=a(N,"\u3002"),N.forEach(s),S=m(C),E(R.$$.fragment,C),H=m(C),A=p(C,"P",{});var z=i(A);I=a(z,"Next stop: the model itself."),z.forEach(s)},m(C,N){n(C,u,N),l(u,j),l(u,d),l(d,$),l(u,q),l(u,v),l(v,b),l(u,T),n(C,S,N),x(R,C,N),n(C,H,N),n(C,A,N),l(A,I),M=!0},i(C){M||(k(R.$$.fragment,C),M=!0)},o(C){g(R.$$.fragment,C),M=!1},d(C){C&&s(u),C&&s(S),y(R,C),C&&s(H),C&&s(A)}}}function Hc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u7B2C\u4E8C\u7EC4\u6807\u7B7E\u7684\u957F\u5EA6\u5DF2\u7ECF\u4F7F\u7528 "),d=o("code"),$=t("-100"),q=t(" \u586B\u5145\u5230\u4E0E\u7B2C\u4E00\u7EC4\u6807\u7B7E\u76F8\u540C\u3002")},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u7B2C\u4E8C\u7EC4\u6807\u7B7E\u7684\u957F\u5EA6\u5DF2\u7ECF\u4F7F\u7528 "),d=p(b,"CODE",{});var T=i(d);$=a(T,"-100"),T.forEach(s),q=a(b," \u586B\u5145\u5230\u4E0E\u7B2C\u4E00\u7EC4\u6807\u7B7E\u76F8\u540C\u3002"),b.forEach(s)},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},i:vc,o:vc,d(v){v&&s(u)}}}function Ec(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te,B,ee,U,Z,L,se,J,pe,fe,ie,Se,re,Ns,js,ue,Be,Ls,ae,Dl,ke,je,_e,Lt,rl,de,Ft,gs,ge,Pl,Te,vs,nl,Ne,ws,ol,ve,Le,ce,Es,xs,lt,zl,De,cs,Fe,le,pl,es,Al,ss,ls,he,fs,il,cl,fl,ml,Il,ts,ul,be,_l,ms,tt,Rl,as,we,Me,ne,Fs,He,at,Ms,Ee,Hs,ys,Gs,Sl,Pe,Os,Us,rs,Bl,Cs,ns,dl,Ge,hl,xe,os,Ue,us,bl,ye,Nl,_s;return Q=new P({props:{code:`id2label = {i: label for i, label in enumerate(label_names)}
label2id = {v: k for k, v in id2label.items()}`,highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`}}),L=new P({props:{code:`from transformers import TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`}}),Be=new P({props:{code:"model.config.num_labels",highlighted:"model.config.num_labels"}}),ae=new P({props:{code:"9",highlighted:'<span class="hljs-number">9</span>'}}),ke=new Dr({props:{warning:!0,$$slots:{default:[Gc]},$$scope:{ctx:F}}}),ge=new P({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()`}}),ve=new P({props:{code:"huggingface-cli login",highlighted:"huggingface-cli login"}}),ss=new P({props:{code:`from transformers import create_optimizer
import tensorflow as tf

# Train in mixed-precision float16
# Comment this line out if you're using a GPU that will not benefit from this
tf.keras.mixed_precision.set_global_policy("mixed_float16")

# The number of training steps is the number of samples in the dataset, divided by the batch size then multiplied
# by the total number of epochs. Note that the tf_train_dataset here is a batched tf.data.Dataset,
# not the original Hugging Face Dataset, so its len() is already num_samples // batch_size.
num_epochs = 3
num_train_steps = len(tf_train_dataset) * num_epochs

optimizer, schedule = create_optimizer(
    init_lr=2e-5,
    num_warmup_steps=0,
    num_train_steps=num_train_steps,
    weight_decay_rate=0.01,
)
model.compile(optimizer=optimizer)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-comment"># Train in mixed-precision float16</span>
<span class="hljs-comment"># Comment this line out if you&#x27;re using a GPU that will not benefit from this</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)

<span class="hljs-comment"># The number of training steps is the number of samples in the dataset, divided by the batch size then multiplied</span>
<span class="hljs-comment"># by the total number of epochs. Note that the tf_train_dataset here is a batched tf.data.Dataset,</span>
<span class="hljs-comment"># not the original Hugging Face Dataset, so its len() is already num_samples // batch_size.</span>
num_epochs = <span class="hljs-number">3</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_epochs

optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">2e-5</span>,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_train_steps=num_train_steps,
    weight_decay_rate=<span class="hljs-number">0.01</span>,
)
model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`}}),we=new P({props:{code:`from transformers.keras_callbacks import PushToHubCallback

callback = PushToHubCallback(output_dir="bert-finetuned-ner", tokenizer=tokenizer)

model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=[callback],
    epochs=num_epochs,
)`,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;bert-finetuned-ner&quot;</span>, tokenizer=tokenizer)

model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=[callback],
    epochs=num_epochs,
)`}}),xe=new Dr({props:{$$slots:{default:[Uc]},$$scope:{ctx:F}}}),{c(){u=o("h3"),j=t("\u5B9A\u4E49\u6A21\u578B"),d=f(),$=o("p"),q=t("\u7531\u4E8E\u6211\u4EEC\u6B63\u5728\u7814\u7A76Token\u5206\u7C7B\u95EE\u9898\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4F7F\u7528 "),v=o("code"),b=t("AutoModelForTokenClassification"),T=t(" \u7C7B\u3002\u5B9A\u4E49\u8FD9\u4E2A\u6A21\u578B\u65F6\u8981\u8BB0\u4F4F\u7684\u4E3B\u8981\u4E8B\u60C5\u662F\u4F20\u9012\u4E00\u4E9B\u5173\u4E8E\u6211\u4EEC\u7684\u6807\u7B7E\u6570\u91CF\u7684\u4FE1\u606F\u3002\u6267\u884C\u6B64\u64CD\u4F5C\u7684\u6700\u7B80\u5355\u65B9\u6CD5\u662F\u5C06\u8BE5\u6570\u5B57\u4F20\u9012\u7ED9 "),S=o("code"),R=t("num_labels"),H=t(" \u53C2\u6570\uFF0C\u4F46\u662F\u5982\u679C\u6211\u4EEC\u60F3\u8981\u4E00\u4E2A\u5F88\u597D\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728\u672C\u8282\u5F00\u5934\u770B\u5230\u7684\u90A3\u6837\uFF0C\u6700\u597D\u8BBE\u7F6E\u6B63\u786E\u7684\u6807\u7B7E\u5BF9\u5E94\u5173\u7CFB\u3002"),A=f(),I=o("p"),M=t("\u5B83\u4EEC\u5E94\u8BE5\u7531\u4E24\u4E2A\u5B57\u5178\u8BBE\u7F6E\uFF0C "),C=o("code"),N=t("id2label"),K=t(" \u548C "),X=o("code"),z=t("label2id"),W=t(" \uFF0C\u5176\u4E2D\u5305\u542B\u4ECE ID \u5230\u6807\u7B7E\u7684\u6620\u5C04\uFF0C\u53CD\u4E4B\u4EA6\u7136\uFF1A"),G=f(),w(Q.$$.fragment),Y=f(),V=o("p"),te=t("\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4EEC\u4F20\u9012\u7ED9 "),B=o("code"),ee=t("AutoModelForTokenClassification.from_pretrained()"),U=t(" \u65B9\u6CD5\uFF0C\u5B83\u4EEC\u5C06\u5728\u6A21\u578B\u7684\u914D\u7F6E\u4E2D\u8BBE\u7F6E\uFF0C\u7136\u540E\u4FDD\u5B58\u5E76\u4E0A\u4F20\u5230Hub\uFF1A"),Z=f(),w(L.$$.fragment),se=f(),J=o("p"),pe=t("\u5C31\u50CF\u6211\u4EEC\u5728"),fe=o("a"),ie=t("\u7B2C\u4E09\u7AE0"),Se=t(",\u5B9A\u4E49\u6211\u4EEC\u7684 "),re=o("code"),Ns=t("AutoModelForSequenceClassification"),js=t(" \uFF0C\u521B\u5EFA\u6A21\u578B\u4F1A\u53D1\u51FA\u8B66\u544A\uFF0C\u63D0\u793A\u4E00\u4E9B\u6743\u91CD\u672A\u88AB\u4F7F\u7528\uFF08\u6765\u81EA\u9884\u8BAD\u7EC3\u5934\u7684\u6743\u91CD\uFF09\u548C\u4E00\u4E9B\u5176\u4ED6\u6743\u91CD\u88AB\u968F\u673A\u521D\u59CB\u5316\uFF08\u6765\u81EA\u65B0Token\u5206\u7C7B\u5934\u7684\u6743\u91CD\uFF09\uFF0C\u6211\u4EEC\u5C06\u8981\u8BAD\u7EC3\u8FD9\u4E2A\u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5728\u4E00\u5206\u949F\u5185\u5B8C\u6210\uFF0C\u4F46\u9996\u5148\u8BA9\u6211\u4EEC\u4ED4\u7EC6\u68C0\u67E5\u6211\u4EEC\u7684\u6A21\u578B\u662F\u5426\u5177\u6709\u6B63\u786E\u6570\u91CF\u7684\u6807\u7B7E\uFF1A"),ue=f(),w(Be.$$.fragment),Ls=f(),w(ae.$$.fragment),Dl=f(),w(ke.$$.fragment),je=f(),_e=o("h3"),Lt=t("\u5FAE\u8C03\u6A21\u578B"),rl=f(),de=o("p"),Ft=t("\u73B0\u5728\uFF0C\u6211\u4EEC\u5DF2\u51C6\u5907\u597D\u8BAD\u7EC3\u6A21\u578B\u4E86\uFF01\u4E0D\u8FC7\uFF0C\u6211\u4EEC\u9996\u5148\u8981\u505A\u4E24\u4EF6\u4E8B\uFF1A\u5E94\u8BE5\u767B\u5F55\u5230Hugging Face\u5E76\u5B9A\u4E49\u6211\u4EEC\u7684\u8BAD\u7EC3\u8D85\u53C2\u6570\u3002\u5982\u679C\u4F60\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u6709\u4E00\u4E2A\u4FBF\u5229\u529F\u80FD\u53EF\u4EE5\u5E2E\u52A9\u4F60\u505A\u5230\u8FD9\u4E00\u70B9\uFF1A"),gs=f(),w(ge.$$.fragment),Pl=f(),Te=o("p"),vs=t("\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u8D26\u53F7\u548C\u5BC6\u7801\u3002"),nl=f(),Ne=o("p"),ws=t("\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),ol=f(),w(ve.$$.fragment),Le=f(),ce=o("p"),Es=t("\u767B\u5F55\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u51C6\u5907\u7F16\u8BD1\u6A21\u578B\u6240\u9700\u7684\u4E00\u5207\u3002\u{1F917} Transformers\u63D0\u4F9B\u4E86\u4E00\u4E2A\u65B9\u4FBF\u7684"),xs=o("code"),lt=t("create_optimizer()"),zl=t(" \u51FD\u6570\uFF0C\u8BE5\u51FD\u6570\u5C06\u4E3A\u60A8\u63D0\u4F9B\u4E00\u4E2A"),De=o("code"),cs=t("AdamW"),Fe=t("\u4F18\u5316\u5668\uFF0C\u5176\u4E2D\u5305\u542B\u9002\u5F53\u7684\u6743\u91CD\u8870\u51CF\u548C\u5B66\u4E60\u901F\u7387\u8870\u51CF\u8BBE\u7F6E\uFF0C\u4E0E\u5185\u7F6E\u7684"),le=o("code"),pl=t("Adam"),es=t("\u4F18\u5316\u5668\u76F8\u4F3C\uFF0C\u8FD9\u4E24\u8005\u90FD\u5C06\u63D0\u9AD8\u6A21\u578B\u7684\u6027\u80FD\uFF1A"),Al=f(),w(ss.$$.fragment),ls=f(),he=o("p"),fs=t("\u8FD8\u8981\u6CE8\u610F\uFF0C\u6211\u4EEC\u4E0D\u4E3A"),il=o("code"),cl=t("compile()"),fl=t("\u63D0\u4F9B"),ml=o("code"),Il=t("loss"),ts=t("\u53C2\u6570\u3002\u8FD9\u662F\u56E0\u4E3A\u6A21\u578B\u5B9E\u9645\u4E0A\u53EF\u4EE5\u5728\u5185\u90E8\u8BA1\u7B97\u635F\u5931 - \u5982\u679C\u60A8\u7F16\u8BD1\u65F6\u6CA1\u6709\u635F\u5931\u5E76\u5728\u8F93\u5165\u5B57\u5178\u4E2D\u63D0\u4F9B\u6807\u7B7E\uFF08\u5C31\u50CF\u6211\u4EEC\u5728\u6570\u636E\u96C6\u4E2D\u6240\u505A\u7684\u90A3\u6837\uFF09\uFF0C\u90A3\u4E48\u6A21\u578B\u5C06\u4F7F\u7528\u8BE5\u5185\u90E8\u635F\u5931\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u8FD9\u5C06\u9002\u7528\u4E8E\u60A8\u9009\u62E9\u7684\u4EFB\u52A1\u548C\u6A21\u578B\u7C7B\u578B\u3002"),ul=f(),be=o("p"),_l=t("\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E00\u4E2A"),ms=o("code"),tt=t("PushToHubCallback"),Rl=t("\uFF0C\u4EE5\u4FBF\u5728\u8BAD\u7EC3\u671F\u95F4\u5C06\u6A21\u578B\u4E0A\u4F20\u5230 Hub\uFF0C\u5E76\u4F7F\u7528\u8BE5\u56DE\u8C03\u6765\u62DF\u5408\u6A21\u578B\uFF1A"),as=f(),w(we.$$.fragment),Me=f(),ne=o("p"),Fs=t("\u60A8\u4E4B\u524D\u5DF2\u7ECF\u770B\u8FC7\u5176\u4E2D\u7684\u5927\u90E8\u5206\u5185\u5BB9\uFF1A\u6211\u4EEC\u8BBE\u7F6E\u4E86\u4E00\u4E9B\u8D85\u53C2\u6570\uFF08\u4F8B\u5982\u5B66\u4E60\u7387\u3001\u8981\u8BAD\u7EC3\u7684 epoch \u6570\u548C\u6743\u91CD\u8870\u51CF\uFF09\uFF0C\u7136\u540E\u6211\u4EEC\u6307\u5B9A "),He=o("code"),at=t("push_to_hub=True"),Ms=t(" \u8868\u660E\u6211\u4EEC\u60F3\u8981\u4FDD\u5B58\u6A21\u578B\u5E76\u5728\u6BCF\u4E2A\u65F6\u671F\u7ED3\u675F\u65F6\u5BF9\u5176\u8FDB\u884C\u8BC4\u4F30\uFF0C\u5E76\u4E14\u6211\u4EEC\u60F3\u8981\u5C06\u6211\u4EEC\u7684\u7ED3\u679C\u4E0A\u4F20\u5230\u6A21\u578B\u4E2D\u5FC3\u3002\u8BF7\u6CE8\u610F\uFF0C\u53EF\u4EE5\u4F7F\u7528hub_model_id\u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0(\u7279\u522B\u662F\uFF0C\u5FC5\u987B\u4F7F\u7528\u8FD9\u4E2A\u53C2\u6570\u6765\u63A8\u9001\u5230\u4E00\u4E2A\u7EC4\u7EC7)\u3002\u4F8B\u5982\uFF0C\u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230"),Ee=o("a"),Hs=o("code"),ys=t("huggingface-course"),Gs=t(" organization"),Sl=t(", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),Pe=o("code"),Os=t("hub_model_id=huggingface-course/bert-finetuned-ner"),Us=t(" \u5230 "),rs=o("code"),Bl=t("TrainingArguments"),Cs=t(" .\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u60A8\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u60A8\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D\uFF0C\u56E0\u6B64\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\u5B83\u5C06\u662F "),ns=o("code"),dl=t("sgugger/bert-finetuned-ner"),Ge=t(" ."),hl=f(),w(xe.$$.fragment),os=f(),Ue=o("p"),us=t("\u8BF7\u6CE8\u610F\uFF0C\u5F53\u8BAD\u7EC3\u53D1\u751F\u65F6\uFF0C\u6BCF\u6B21\u4FDD\u5B58\u6A21\u578B\u65F6\uFF08\u8FD9\u91CC\u662F\u6BCF\u4E2Aepooch\uFF09\uFF0C\u5B83\u90FD\u4F1A\u5728\u540E\u53F0\u4E0A\u4F20\u5230 Hub\u3002\u8FD9\u6837\uFF0C\u5982\u6709\u5FC5\u8981\uFF0C\u60A8\u5C06\u80FD\u591F\u5728\u53E6\u4E00\u53F0\u673A\u5668\u4E0A\u7EE7\u7EED\u60A8\u7684\u8BAD\u7EC3\u3002"),bl=f(),ye=o("p"),Nl=t("\u5728\u6B64\u9636\u6BB5\uFF0C\u60A8\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u4E2D\u5FC3\u4E0A\u7684\u63A8\u7406\u5C0F\u7EC4\u4EF6\u6765\u6D4B\u8BD5\u6A21\u578B\u5E76\u4E0E\u670B\u53CB\u5171\u4EAB\u3002\u60A8\u5DF2\u7ECF\u6210\u529F\u5FAE\u8C03\u4E86\u4EE4\u724C\u5206\u7C7B\u4EFB\u52A1\u7684\u6A21\u578B - \u606D\u559C\uFF01\u4F46\u662F\uFF0C\u6211\u4EEC\u7684\u6A21\u578B\u5230\u5E95\u6709\u591A\u597D\u5462\uFF1F\u6211\u4EEC\u5E94\u8BE5\u8BC4\u4F30\u4E00\u4E9B\u6307\u6807\u6765\u627E\u51FA\u7B54\u6848\u3002"),this.h()},l(_){u=p(_,"H3",{id:!0});var D=i(u);j=a(D,"\u5B9A\u4E49\u6A21\u578B"),D.forEach(s),d=m(_),$=p(_,"P",{});var Ws=i($);q=a(Ws,"\u7531\u4E8E\u6211\u4EEC\u6B63\u5728\u7814\u7A76Token\u5206\u7C7B\u95EE\u9898\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4F7F\u7528 "),v=p(Ws,"CODE",{});var $l=i(v);b=a($l,"AutoModelForTokenClassification"),$l.forEach(s),T=a(Ws," \u7C7B\u3002\u5B9A\u4E49\u8FD9\u4E2A\u6A21\u578B\u65F6\u8981\u8BB0\u4F4F\u7684\u4E3B\u8981\u4E8B\u60C5\u662F\u4F20\u9012\u4E00\u4E9B\u5173\u4E8E\u6211\u4EEC\u7684\u6807\u7B7E\u6570\u91CF\u7684\u4FE1\u606F\u3002\u6267\u884C\u6B64\u64CD\u4F5C\u7684\u6700\u7B80\u5355\u65B9\u6CD5\u662F\u5C06\u8BE5\u6570\u5B57\u4F20\u9012\u7ED9 "),S=p(Ws,"CODE",{});var Xs=i(S);R=a(Xs,"num_labels"),Xs.forEach(s),H=a(Ws," \u53C2\u6570\uFF0C\u4F46\u662F\u5982\u679C\u6211\u4EEC\u60F3\u8981\u4E00\u4E2A\u5F88\u597D\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728\u672C\u8282\u5F00\u5934\u770B\u5230\u7684\u90A3\u6837\uFF0C\u6700\u597D\u8BBE\u7F6E\u6B63\u786E\u7684\u6807\u7B7E\u5BF9\u5E94\u5173\u7CFB\u3002"),Ws.forEach(s),A=m(_),I=p(_,"P",{});var Zs=i(I);M=a(Zs,"\u5B83\u4EEC\u5E94\u8BE5\u7531\u4E24\u4E2A\u5B57\u5178\u8BBE\u7F6E\uFF0C "),C=p(Zs,"CODE",{});var kl=i(C);N=a(kl,"id2label"),kl.forEach(s),K=a(Zs," \u548C "),X=p(Zs,"CODE",{});var qs=i(X);z=a(qs,"label2id"),qs.forEach(s),W=a(Zs," \uFF0C\u5176\u4E2D\u5305\u542B\u4ECE ID \u5230\u6807\u7B7E\u7684\u6620\u5C04\uFF0C\u53CD\u4E4B\u4EA6\u7136\uFF1A"),Zs.forEach(s),G=m(_),E(Q.$$.fragment,_),Y=m(_),V=p(_,"P",{});var Ll=i(V);te=a(Ll,"\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4EEC\u4F20\u9012\u7ED9 "),B=p(Ll,"CODE",{});var Ts=i(B);ee=a(Ts,"AutoModelForTokenClassification.from_pretrained()"),Ts.forEach(s),U=a(Ll," \u65B9\u6CD5\uFF0C\u5B83\u4EEC\u5C06\u5728\u6A21\u578B\u7684\u914D\u7F6E\u4E2D\u8BBE\u7F6E\uFF0C\u7136\u540E\u4FDD\u5B58\u5E76\u4E0A\u4F20\u5230Hub\uFF1A"),Ll.forEach(s),Z=m(_),E(L.$$.fragment,_),se=m(_),J=p(_,"P",{});var Ks=i(J);pe=a(Ks,"\u5C31\u50CF\u6211\u4EEC\u5728"),fe=p(Ks,"A",{href:!0});var Mt=i(fe);ie=a(Mt,"\u7B2C\u4E09\u7AE0"),Mt.forEach(s),Se=a(Ks,",\u5B9A\u4E49\u6211\u4EEC\u7684 "),re=p(Ks,"CODE",{});var jl=i(re);Ns=a(jl,"AutoModelForSequenceClassification"),jl.forEach(s),js=a(Ks," \uFF0C\u521B\u5EFA\u6A21\u578B\u4F1A\u53D1\u51FA\u8B66\u544A\uFF0C\u63D0\u793A\u4E00\u4E9B\u6743\u91CD\u672A\u88AB\u4F7F\u7528\uFF08\u6765\u81EA\u9884\u8BAD\u7EC3\u5934\u7684\u6743\u91CD\uFF09\u548C\u4E00\u4E9B\u5176\u4ED6\u6743\u91CD\u88AB\u968F\u673A\u521D\u59CB\u5316\uFF08\u6765\u81EA\u65B0Token\u5206\u7C7B\u5934\u7684\u6743\u91CD\uFF09\uFF0C\u6211\u4EEC\u5C06\u8981\u8BAD\u7EC3\u8FD9\u4E2A\u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5728\u4E00\u5206\u949F\u5185\u5B8C\u6210\uFF0C\u4F46\u9996\u5148\u8BA9\u6211\u4EEC\u4ED4\u7EC6\u68C0\u67E5\u6211\u4EEC\u7684\u6A21\u578B\u662F\u5426\u5177\u6709\u6B63\u786E\u6570\u91CF\u7684\u6807\u7B7E\uFF1A"),Ks.forEach(s),ue=m(_),E(Be.$$.fragment,_),Ls=m(_),E(ae.$$.fragment,_),Dl=m(_),E(ke.$$.fragment,_),je=m(_),_e=p(_,"H3",{id:!0});var Vs=i(_e);Lt=a(Vs,"\u5FAE\u8C03\u6A21\u578B"),Vs.forEach(s),rl=m(_),de=p(_,"P",{});var Ht=i(de);Ft=a(Ht,"\u73B0\u5728\uFF0C\u6211\u4EEC\u5DF2\u51C6\u5907\u597D\u8BAD\u7EC3\u6A21\u578B\u4E86\uFF01\u4E0D\u8FC7\uFF0C\u6211\u4EEC\u9996\u5148\u8981\u505A\u4E24\u4EF6\u4E8B\uFF1A\u5E94\u8BE5\u767B\u5F55\u5230Hugging Face\u5E76\u5B9A\u4E49\u6211\u4EEC\u7684\u8BAD\u7EC3\u8D85\u53C2\u6570\u3002\u5982\u679C\u4F60\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u6709\u4E00\u4E2A\u4FBF\u5229\u529F\u80FD\u53EF\u4EE5\u5E2E\u52A9\u4F60\u505A\u5230\u8FD9\u4E00\u70B9\uFF1A"),Ht.forEach(s),gs=m(_),E(ge.$$.fragment,_),Pl=m(_),Te=p(_,"P",{});var Fl=i(Te);vs=a(Fl,"\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u8D26\u53F7\u548C\u5BC6\u7801\u3002"),Fl.forEach(s),nl=m(_),Ne=p(_,"P",{});var We=i(Ne);ws=a(We,"\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),We.forEach(s),ol=m(_),E(ve.$$.fragment,_),Le=m(_),ce=p(_,"P",{});var Xe=i(ce);Es=a(Xe,"\u767B\u5F55\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u51C6\u5907\u7F16\u8BD1\u6A21\u578B\u6240\u9700\u7684\u4E00\u5207\u3002\u{1F917} Transformers\u63D0\u4F9B\u4E86\u4E00\u4E2A\u65B9\u4FBF\u7684"),xs=p(Xe,"CODE",{});var ps=i(xs);lt=a(ps,"create_optimizer()"),ps.forEach(s),zl=a(Xe," \u51FD\u6570\uFF0C\u8BE5\u51FD\u6570\u5C06\u4E3A\u60A8\u63D0\u4F9B\u4E00\u4E2A"),De=p(Xe,"CODE",{});var rt=i(De);cs=a(rt,"AdamW"),rt.forEach(s),Fe=a(Xe,"\u4F18\u5316\u5668\uFF0C\u5176\u4E2D\u5305\u542B\u9002\u5F53\u7684\u6743\u91CD\u8870\u51CF\u548C\u5B66\u4E60\u901F\u7387\u8870\u51CF\u8BBE\u7F6E\uFF0C\u4E0E\u5185\u7F6E\u7684"),le=p(Xe,"CODE",{});var Ze=i(le);pl=a(Ze,"Adam"),Ze.forEach(s),es=a(Xe,"\u4F18\u5316\u5668\u76F8\u4F3C\uFF0C\u8FD9\u4E24\u8005\u90FD\u5C06\u63D0\u9AD8\u6A21\u578B\u7684\u6027\u80FD\uFF1A"),Xe.forEach(s),Al=m(_),E(ss.$$.fragment,_),ls=m(_),he=p(_,"P",{});var Ke=i(he);fs=a(Ke,"\u8FD8\u8981\u6CE8\u610F\uFF0C\u6211\u4EEC\u4E0D\u4E3A"),il=p(Ke,"CODE",{});var Ys=i(il);cl=a(Ys,"compile()"),Ys.forEach(s),fl=a(Ke,"\u63D0\u4F9B"),ml=p(Ke,"CODE",{});var is=i(ml);Il=a(is,"loss"),is.forEach(s),ts=a(Ke,"\u53C2\u6570\u3002\u8FD9\u662F\u56E0\u4E3A\u6A21\u578B\u5B9E\u9645\u4E0A\u53EF\u4EE5\u5728\u5185\u90E8\u8BA1\u7B97\u635F\u5931 - \u5982\u679C\u60A8\u7F16\u8BD1\u65F6\u6CA1\u6709\u635F\u5931\u5E76\u5728\u8F93\u5165\u5B57\u5178\u4E2D\u63D0\u4F9B\u6807\u7B7E\uFF08\u5C31\u50CF\u6211\u4EEC\u5728\u6570\u636E\u96C6\u4E2D\u6240\u505A\u7684\u90A3\u6837\uFF09\uFF0C\u90A3\u4E48\u6A21\u578B\u5C06\u4F7F\u7528\u8BE5\u5185\u90E8\u635F\u5931\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u8FD9\u5C06\u9002\u7528\u4E8E\u60A8\u9009\u62E9\u7684\u4EFB\u52A1\u548C\u6A21\u578B\u7C7B\u578B\u3002"),Ke.forEach(s),ul=m(_),be=p(_,"P",{});var Ml=i(be);_l=a(Ml,"\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E00\u4E2A"),ms=p(Ml,"CODE",{});var Js=i(ms);tt=a(Js,"PushToHubCallback"),Js.forEach(s),Rl=a(Ml,"\uFF0C\u4EE5\u4FBF\u5728\u8BAD\u7EC3\u671F\u95F4\u5C06\u6A21\u578B\u4E0A\u4F20\u5230 Hub\uFF0C\u5E76\u4F7F\u7528\u8BE5\u56DE\u8C03\u6765\u62DF\u5408\u6A21\u578B\uFF1A"),Ml.forEach(s),as=m(_),E(we.$$.fragment,_),Me=m(_),ne=p(_,"P",{});var Oe=i(ne);Fs=a(Oe,"\u60A8\u4E4B\u524D\u5DF2\u7ECF\u770B\u8FC7\u5176\u4E2D\u7684\u5927\u90E8\u5206\u5185\u5BB9\uFF1A\u6211\u4EEC\u8BBE\u7F6E\u4E86\u4E00\u4E9B\u8D85\u53C2\u6570\uFF08\u4F8B\u5982\u5B66\u4E60\u7387\u3001\u8981\u8BAD\u7EC3\u7684 epoch \u6570\u548C\u6743\u91CD\u8870\u51CF\uFF09\uFF0C\u7136\u540E\u6211\u4EEC\u6307\u5B9A "),He=p(Oe,"CODE",{});var Gt=i(He);at=a(Gt,"push_to_hub=True"),Gt.forEach(s),Ms=a(Oe," \u8868\u660E\u6211\u4EEC\u60F3\u8981\u4FDD\u5B58\u6A21\u578B\u5E76\u5728\u6BCF\u4E2A\u65F6\u671F\u7ED3\u675F\u65F6\u5BF9\u5176\u8FDB\u884C\u8BC4\u4F30\uFF0C\u5E76\u4E14\u6211\u4EEC\u60F3\u8981\u5C06\u6211\u4EEC\u7684\u7ED3\u679C\u4E0A\u4F20\u5230\u6A21\u578B\u4E2D\u5FC3\u3002\u8BF7\u6CE8\u610F\uFF0C\u53EF\u4EE5\u4F7F\u7528hub_model_id\u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0(\u7279\u522B\u662F\uFF0C\u5FC5\u987B\u4F7F\u7528\u8FD9\u4E2A\u53C2\u6570\u6765\u63A8\u9001\u5230\u4E00\u4E2A\u7EC4\u7EC7)\u3002\u4F8B\u5982\uFF0C\u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230"),Ee=p(Oe,"A",{href:!0,rel:!0});var Qs=i(Ee);Hs=p(Qs,"CODE",{});var $e=i(Hs);ys=a($e,"huggingface-course"),$e.forEach(s),Gs=a(Qs," organization"),Qs.forEach(s),Sl=a(Oe,", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),Pe=p(Oe,"CODE",{});var gl=i(Pe);Os=a(gl,"hub_model_id=huggingface-course/bert-finetuned-ner"),gl.forEach(s),Us=a(Oe," \u5230 "),rs=p(Oe,"CODE",{});var vl=i(rs);Bl=a(vl,"TrainingArguments"),vl.forEach(s),Cs=a(Oe," .\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u60A8\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u60A8\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D\uFF0C\u56E0\u6B64\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\u5B83\u5C06\u662F "),ns=p(Oe,"CODE",{});var el=i(ns);dl=a(el,"sgugger/bert-finetuned-ner"),el.forEach(s),Ge=a(Oe," ."),Oe.forEach(s),hl=m(_),E(xe.$$.fragment,_),os=m(_),Ue=p(_,"P",{});var nt=i(Ue);us=a(nt,"\u8BF7\u6CE8\u610F\uFF0C\u5F53\u8BAD\u7EC3\u53D1\u751F\u65F6\uFF0C\u6BCF\u6B21\u4FDD\u5B58\u6A21\u578B\u65F6\uFF08\u8FD9\u91CC\u662F\u6BCF\u4E2Aepooch\uFF09\uFF0C\u5B83\u90FD\u4F1A\u5728\u540E\u53F0\u4E0A\u4F20\u5230 Hub\u3002\u8FD9\u6837\uFF0C\u5982\u6709\u5FC5\u8981\uFF0C\u60A8\u5C06\u80FD\u591F\u5728\u53E6\u4E00\u53F0\u673A\u5668\u4E0A\u7EE7\u7EED\u60A8\u7684\u8BAD\u7EC3\u3002"),nt.forEach(s),bl=m(_),ye=p(_,"P",{});var Ds=i(ye);Nl=a(Ds,"\u5728\u6B64\u9636\u6BB5\uFF0C\u60A8\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u4E2D\u5FC3\u4E0A\u7684\u63A8\u7406\u5C0F\u7EC4\u4EF6\u6765\u6D4B\u8BD5\u6A21\u578B\u5E76\u4E0E\u670B\u53CB\u5171\u4EAB\u3002\u60A8\u5DF2\u7ECF\u6210\u529F\u5FAE\u8C03\u4E86\u4EE4\u724C\u5206\u7C7B\u4EFB\u52A1\u7684\u6A21\u578B - \u606D\u559C\uFF01\u4F46\u662F\uFF0C\u6211\u4EEC\u7684\u6A21\u578B\u5230\u5E95\u6709\u591A\u597D\u5462\uFF1F\u6211\u4EEC\u5E94\u8BE5\u8BC4\u4F30\u4E00\u4E9B\u6307\u6807\u6765\u627E\u51FA\u7B54\u6848\u3002"),Ds.forEach(s),this.h()},h(){O(u,"id",""),O(fe,"href","/course/chapter3"),O(_e,"id",""),O(Ee,"href","https://huggingface.co/huggingface-course"),O(Ee,"rel","nofollow")},m(_,D){n(_,u,D),l(u,j),n(_,d,D),n(_,$,D),l($,q),l($,v),l(v,b),l($,T),l($,S),l(S,R),l($,H),n(_,A,D),n(_,I,D),l(I,M),l(I,C),l(C,N),l(I,K),l(I,X),l(X,z),l(I,W),n(_,G,D),x(Q,_,D),n(_,Y,D),n(_,V,D),l(V,te),l(V,B),l(B,ee),l(V,U),n(_,Z,D),x(L,_,D),n(_,se,D),n(_,J,D),l(J,pe),l(J,fe),l(fe,ie),l(J,Se),l(J,re),l(re,Ns),l(J,js),n(_,ue,D),x(Be,_,D),n(_,Ls,D),x(ae,_,D),n(_,Dl,D),x(ke,_,D),n(_,je,D),n(_,_e,D),l(_e,Lt),n(_,rl,D),n(_,de,D),l(de,Ft),n(_,gs,D),x(ge,_,D),n(_,Pl,D),n(_,Te,D),l(Te,vs),n(_,nl,D),n(_,Ne,D),l(Ne,ws),n(_,ol,D),x(ve,_,D),n(_,Le,D),n(_,ce,D),l(ce,Es),l(ce,xs),l(xs,lt),l(ce,zl),l(ce,De),l(De,cs),l(ce,Fe),l(ce,le),l(le,pl),l(ce,es),n(_,Al,D),x(ss,_,D),n(_,ls,D),n(_,he,D),l(he,fs),l(he,il),l(il,cl),l(he,fl),l(he,ml),l(ml,Il),l(he,ts),n(_,ul,D),n(_,be,D),l(be,_l),l(be,ms),l(ms,tt),l(be,Rl),n(_,as,D),x(we,_,D),n(_,Me,D),n(_,ne,D),l(ne,Fs),l(ne,He),l(He,at),l(ne,Ms),l(ne,Ee),l(Ee,Hs),l(Hs,ys),l(Ee,Gs),l(ne,Sl),l(ne,Pe),l(Pe,Os),l(ne,Us),l(ne,rs),l(rs,Bl),l(ne,Cs),l(ne,ns),l(ns,dl),l(ne,Ge),n(_,hl,D),x(xe,_,D),n(_,os,D),n(_,Ue,D),l(Ue,us),n(_,bl,D),n(_,ye,D),l(ye,Nl),_s=!0},i(_){_s||(k(Q.$$.fragment,_),k(L.$$.fragment,_),k(Be.$$.fragment,_),k(ae.$$.fragment,_),k(ke.$$.fragment,_),k(ge.$$.fragment,_),k(ve.$$.fragment,_),k(ss.$$.fragment,_),k(we.$$.fragment,_),k(xe.$$.fragment,_),_s=!0)},o(_){g(Q.$$.fragment,_),g(L.$$.fragment,_),g(Be.$$.fragment,_),g(ae.$$.fragment,_),g(ke.$$.fragment,_),g(ge.$$.fragment,_),g(ve.$$.fragment,_),g(ss.$$.fragment,_),g(we.$$.fragment,_),g(xe.$$.fragment,_),_s=!1},d(_){_&&s(u),_&&s(d),_&&s($),_&&s(A),_&&s(I),_&&s(G),y(Q,_),_&&s(Y),_&&s(V),_&&s(Z),y(L,_),_&&s(se),_&&s(J),_&&s(ue),y(Be,_),_&&s(Ls),y(ae,_),_&&s(Dl),y(ke,_),_&&s(je),_&&s(_e),_&&s(rl),_&&s(de),_&&s(gs),y(ge,_),_&&s(Pl),_&&s(Te),_&&s(nl),_&&s(Ne),_&&s(ol),y(ve,_),_&&s(Le),_&&s(ce),_&&s(Al),y(ss,_),_&&s(ls),_&&s(he),_&&s(ul),_&&s(be),_&&s(as),y(we,_),_&&s(Me),_&&s(ne),_&&s(hl),y(xe,_),_&&s(os),_&&s(Ue),_&&s(bl),_&&s(ye)}}}function Gc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u26A0\uFE0F \u5982\u679C\u60A8\u7684\u6A21\u578B\u6807\u7B7E\u6570\u91CF\u9519\u8BEF\uFF0C\u5219\u5728\u7A0D\u540E\u8C03\u7528 "),d=o("code"),$=t("model.fit()"),q=t(" \u65F6\u5C06\u6536\u5230\u4E00\u4E2A\u6A21\u7CCA\u7684\u9519\u8BEF\u3002\u8C03\u8BD5\u8D77\u6765\u53EF\u80FD\u5F88\u70E6\u4EBA\uFF0C\u56E0\u6B64\u8BF7\u786E\u4FDD\u6267\u884C\u6B64\u68C0\u67E5\u4EE5\u786E\u8BA4\u60A8\u5177\u6709\u9884\u671F\u7684\u6807\u7B7E\u6570\u3002")},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u26A0\uFE0F \u5982\u679C\u60A8\u7684\u6A21\u578B\u6807\u7B7E\u6570\u91CF\u9519\u8BEF\uFF0C\u5219\u5728\u7A0D\u540E\u8C03\u7528 "),d=p(b,"CODE",{});var T=i(d);$=a(T,"model.fit()"),T.forEach(s),q=a(b," \u65F6\u5C06\u6536\u5230\u4E00\u4E2A\u6A21\u7CCA\u7684\u9519\u8BEF\u3002\u8C03\u8BD5\u8D77\u6765\u53EF\u80FD\u5F88\u70E6\u4EBA\uFF0C\u56E0\u6B64\u8BF7\u786E\u4FDD\u6267\u884C\u6B64\u68C0\u67E5\u4EE5\u786E\u8BA4\u60A8\u5177\u6709\u9884\u671F\u7684\u6807\u7B7E\u6570\u3002"),b.forEach(s)},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Uc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u{1F4A1} \u5982\u679C\u60A8\u6B63\u5728\u4F7F\u7528\u7684\u8F93\u51FA\u76EE\u5F55\u5DF2\u7ECF\u5B58\u5728\uFF0C\u90A3\u4E48\u8F93\u51FA\u76EE\u5F55\u5FC5\u987B\u662F\u4ECE\u540C\u4E00\u4E2A\u5B58\u50A8\u5E93clone\u4E0B\u6765\u7684\u3002\u5982\u679C\u4E0D\u662F\uFF0C\u60A8\u5C06\u5728\u58F0\u660E "),d=o("code"),$=t("model.fit()"),q=t(" \u65F6\u9047\u5230\u9519\u8BEF\uFF0C\u5E76\u4E14\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u65B0\u540D\u79F0\u3002")},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u{1F4A1} \u5982\u679C\u60A8\u6B63\u5728\u4F7F\u7528\u7684\u8F93\u51FA\u76EE\u5F55\u5DF2\u7ECF\u5B58\u5728\uFF0C\u90A3\u4E48\u8F93\u51FA\u76EE\u5F55\u5FC5\u987B\u662F\u4ECE\u540C\u4E00\u4E2A\u5B58\u50A8\u5E93clone\u4E0B\u6765\u7684\u3002\u5982\u679C\u4E0D\u662F\uFF0C\u60A8\u5C06\u5728\u58F0\u660E "),d=p(b,"CODE",{});var T=i(d);$=a(T,"model.fit()"),T.forEach(s),q=a(b," \u65F6\u9047\u5230\u9519\u8BEF\uFF0C\u5E76\u4E14\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u65B0\u540D\u79F0\u3002"),b.forEach(s)},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Wc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X;return T=new P({props:{code:"!pip install seqeval",highlighted:"!pip install seqeval"}}),{c(){u=o("p"),j=t("\u7528\u4E8E\u8BC4\u4F30Token\u5206\u7C7B\u9884\u6D4B\u7684\u4F20\u7EDF\u6846\u67B6\u662F "),d=o("a"),$=o("em"),q=t("seqeval"),v=t(". \u8981\u4F7F\u7528\u6B64\u6307\u6807\uFF0C\u6211\u4EEC\u9996\u5148\u9700\u8981\u5B89\u88C5seqeval\u5E93\uFF1A"),b=f(),w(T.$$.fragment),S=f(),R=o("p"),H=t("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u52A0\u8F7D\u5B83 "),A=o("code"),I=t("load_metric()"),M=t(" \u51FD\u6570\u5C31\u50CF\u6211\u4EEC\u5728"),C=o("a"),N=t("\u7B2C\u4E09\u7AE0"),K=t("\u505A\u7684\u90A3\u6837\uFF1A"),this.h()},l(z){u=p(z,"P",{});var W=i(u);j=a(W,"\u7528\u4E8E\u8BC4\u4F30Token\u5206\u7C7B\u9884\u6D4B\u7684\u4F20\u7EDF\u6846\u67B6\u662F "),d=p(W,"A",{href:!0,rel:!0});var G=i(d);$=p(G,"EM",{});var Q=i($);q=a(Q,"seqeval"),Q.forEach(s),G.forEach(s),v=a(W,". \u8981\u4F7F\u7528\u6B64\u6307\u6807\uFF0C\u6211\u4EEC\u9996\u5148\u9700\u8981\u5B89\u88C5seqeval\u5E93\uFF1A"),W.forEach(s),b=m(z),E(T.$$.fragment,z),S=m(z),R=p(z,"P",{});var Y=i(R);H=a(Y,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u52A0\u8F7D\u5B83 "),A=p(Y,"CODE",{});var V=i(A);I=a(V,"load_metric()"),V.forEach(s),M=a(Y," \u51FD\u6570\u5C31\u50CF\u6211\u4EEC\u5728"),C=p(Y,"A",{href:!0});var te=i(C);N=a(te,"\u7B2C\u4E09\u7AE0"),te.forEach(s),K=a(Y,"\u505A\u7684\u90A3\u6837\uFF1A"),Y.forEach(s),this.h()},h(){O(d,"href","https://github.com/chakki-works/seqeval"),O(d,"rel","nofollow"),O(C,"href","/course/chapter3")},m(z,W){n(z,u,W),l(u,j),l(u,d),l(d,$),l($,q),l(u,v),n(z,b,W),x(T,z,W),n(z,S,W),n(z,R,W),l(R,H),l(R,A),l(A,I),l(R,M),l(R,C),l(C,N),l(R,K),X=!0},i(z){X||(k(T.$$.fragment,z),X=!0)},o(z){g(T.$$.fragment,z),X=!1},d(z){z&&s(u),z&&s(b),y(T,z),z&&s(S),z&&s(R)}}}function Xc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te,B,ee;return K=new P({props:{code:"!pip install seqeval",highlighted:"!pip install seqeval"}}),{c(){u=o("p"),j=t("\u4E3A\u4E86\u8BA9 "),d=o("code"),$=t("Trainer"),q=t(" \u5728\u6BCF\u4E2Aepoch\u8BA1\u7B97\u4E00\u4E2A\u5EA6\u91CF\uFF0C\u6211\u4EEC\u9700\u8981\u5B9A\u4E49\u4E00\u4E2A "),v=o("code"),b=t("compute_metrics()"),T=t(" \u51FD\u6570\uFF0C\u8BE5\u51FD\u6570\u63A5\u53D7\u9884\u6D4B\u548C\u6807\u7B7E\u6570\u7EC4\uFF0C\u5E76\u8FD4\u56DE\u4E00\u4E2A\u5305\u542B\u5EA6\u91CF\u540D\u79F0\u548C\u503C\u7684\u5B57\u5178"),S=f(),R=o("p"),H=t("\u7528\u4E8E\u8BC4\u4F30Token\u5206\u7C7B\u9884\u6D4B\u7684\u4F20\u7EDF\u6846\u67B6\u662F "),A=o("a"),I=o("em"),M=t("seqeval"),C=t(". \u8981\u4F7F\u7528\u6B64\u6307\u6807\uFF0C\u6211\u4EEC\u9996\u5148\u9700\u8981\u5B89\u88C5seqeval\u5E93\uFF1A"),N=f(),w(K.$$.fragment),X=f(),z=o("p"),W=t("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u52A0\u8F7D\u5B83 "),G=o("code"),Q=t("load_metric()"),Y=t(" \u51FD\u6570\u5C31\u50CF\u6211\u4EEC\u5728"),V=o("a"),te=t("\u7B2C\u4E09\u7AE0"),B=t("\u505A\u7684\u90A3\u6837\uFF1A"),this.h()},l(U){u=p(U,"P",{});var Z=i(u);j=a(Z,"\u4E3A\u4E86\u8BA9 "),d=p(Z,"CODE",{});var L=i(d);$=a(L,"Trainer"),L.forEach(s),q=a(Z," \u5728\u6BCF\u4E2Aepoch\u8BA1\u7B97\u4E00\u4E2A\u5EA6\u91CF\uFF0C\u6211\u4EEC\u9700\u8981\u5B9A\u4E49\u4E00\u4E2A "),v=p(Z,"CODE",{});var se=i(v);b=a(se,"compute_metrics()"),se.forEach(s),T=a(Z," \u51FD\u6570\uFF0C\u8BE5\u51FD\u6570\u63A5\u53D7\u9884\u6D4B\u548C\u6807\u7B7E\u6570\u7EC4\uFF0C\u5E76\u8FD4\u56DE\u4E00\u4E2A\u5305\u542B\u5EA6\u91CF\u540D\u79F0\u548C\u503C\u7684\u5B57\u5178"),Z.forEach(s),S=m(U),R=p(U,"P",{});var J=i(R);H=a(J,"\u7528\u4E8E\u8BC4\u4F30Token\u5206\u7C7B\u9884\u6D4B\u7684\u4F20\u7EDF\u6846\u67B6\u662F "),A=p(J,"A",{href:!0,rel:!0});var pe=i(A);I=p(pe,"EM",{});var fe=i(I);M=a(fe,"seqeval"),fe.forEach(s),pe.forEach(s),C=a(J,". \u8981\u4F7F\u7528\u6B64\u6307\u6807\uFF0C\u6211\u4EEC\u9996\u5148\u9700\u8981\u5B89\u88C5seqeval\u5E93\uFF1A"),J.forEach(s),N=m(U),E(K.$$.fragment,U),X=m(U),z=p(U,"P",{});var ie=i(z);W=a(ie,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u52A0\u8F7D\u5B83 "),G=p(ie,"CODE",{});var Se=i(G);Q=a(Se,"load_metric()"),Se.forEach(s),Y=a(ie," \u51FD\u6570\u5C31\u50CF\u6211\u4EEC\u5728"),V=p(ie,"A",{href:!0});var re=i(V);te=a(re,"\u7B2C\u4E09\u7AE0"),re.forEach(s),B=a(ie,"\u505A\u7684\u90A3\u6837\uFF1A"),ie.forEach(s),this.h()},h(){O(A,"href","https://github.com/chakki-works/seqeval"),O(A,"rel","nofollow"),O(V,"href","/course/chapter3")},m(U,Z){n(U,u,Z),l(u,j),l(u,d),l(d,$),l(u,q),l(u,v),l(v,b),l(u,T),n(U,S,Z),n(U,R,Z),l(R,H),l(R,A),l(A,I),l(I,M),l(R,C),n(U,N,Z),x(K,U,Z),n(U,X,Z),n(U,z,Z),l(z,W),l(z,G),l(G,Q),l(z,Y),l(z,V),l(V,te),l(z,B),ee=!0},i(U){ee||(k(K.$$.fragment,U),ee=!0)},o(U){g(K.$$.fragment,U),ee=!1},d(U){U&&s(u),U&&s(S),U&&s(R),U&&s(N),y(K,U),U&&s(X),U&&s(z)}}}function Zc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te;return z=new P({props:{code:`import numpy as np

all_predictions = []
all_labels = []
for batch in tf_eval_dataset:
    logits = model.predict(batch)["logits"]
    labels = batch["labels"]
    predictions = np.argmax(logits, axis=-1)
    for prediction, label in zip(predictions, labels):
        for predicted_idx, label_idx in zip(prediction, label):
            if label_idx == -100:
                continue
            all_predictions.append(label_names[predicted_idx])
            all_labels.append(label_names[label_idx])
metric.compute(predictions=[all_predictions], references=[all_labels])`,highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

all_predictions = []
all_labels = []
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> tf_eval_dataset:
    logits = model.predict(batch)[<span class="hljs-string">&quot;logits&quot;</span>]
    labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]
    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)
    <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels):
        <span class="hljs-keyword">for</span> predicted_idx, label_idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label):
            <span class="hljs-keyword">if</span> label_idx == -<span class="hljs-number">100</span>:
                <span class="hljs-keyword">continue</span>
            all_predictions.append(label_names[predicted_idx])
            all_labels.append(label_names[label_idx])
metric.compute(predictions=[all_predictions], references=[all_labels])`}}),G=new P({props:{code:`{'LOC': {'precision': 0.91, 'recall': 0.92, 'f1': 0.91, 'number': 1668},
 'MISC': {'precision': 0.70, 'recall': 0.79, 'f1': 0.74, 'number': 702},
 'ORG': {'precision': 0.85, 'recall': 0.90, 'f1': 0.88, 'number': 1661},
 'PER': {'precision': 0.95, 'recall': 0.95, 'f1': 0.95, 'number': 1617},
 'overall_precision': 0.87,
 'overall_recall': 0.91,
 'overall_f1': 0.89,
 'overall_accuracy': 0.97}`,highlighted:`{<span class="hljs-string">&#x27;LOC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.91</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.92</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.91</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1668</span>},
 <span class="hljs-string">&#x27;MISC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.70</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.79</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.74</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">702</span>},
 <span class="hljs-string">&#x27;ORG&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.85</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.90</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.88</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1661</span>},
 <span class="hljs-string">&#x27;PER&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1617</span>},
 <span class="hljs-string">&#x27;overall_precision&#x27;</span>: <span class="hljs-number">0.87</span>,
 <span class="hljs-string">&#x27;overall_recall&#x27;</span>: <span class="hljs-number">0.91</span>,
 <span class="hljs-string">&#x27;overall_f1&#x27;</span>: <span class="hljs-number">0.89</span>,
 <span class="hljs-string">&#x27;overall_accuracy&#x27;</span>: <span class="hljs-number">0.97</span>}`}}),{c(){u=o("p"),j=t("\u5B83\u8FD4\u56DE\u5F88\u591A\u4FE1\u606F\uFF01\u6211\u4EEC\u83B7\u5F97\u6BCF\u4E2A\u5355\u72EC\u5B9E\u4F53\u4EE5\u53CA\u6574\u4F53\u7684\u51C6\u786E\u7387\u3001\u53EC\u56DE\u7387\u548C F1 \u5206\u6570\u3002\u5BF9\u4E8E\u6211\u4EEC\u7684\u5EA6\u91CF\u8BA1\u7B97\uFF0C\u6211\u4EEC\u5C06\u53EA\u4FDD\u7559\u603B\u5206\uFF0C\u4F46\u53EF\u4EE5\u968F\u610F\u8C03\u6574 "),d=o("code"),$=t("compute_metrics()"),q=t(" \u51FD\u6570\u8FD4\u56DE\u60A8\u60F3\u8981\u67E5\u770B\u7684\u6240\u6709\u6307\u6807\u3002"),v=f(),b=o("p"),T=t("\u8FD9"),S=o("code"),R=t("compute_metrics()"),H=t(" \u51FD\u6570\u9996\u5148\u91C7\u7528 logits \u7684 argmax \u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u9884\u6D4B\uFF08\u50CF\u5F80\u5E38\u4E00\u6837\uFF0Clogits \u548C\u6982\u7387\u7684\u987A\u5E8F\u76F8\u540C\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E0D\u9700\u8981\u5E94\u7528 softmax\uFF09\u3002\u7136\u540E\u6211\u4EEC\u5FC5\u987B\u5C06\u6807\u7B7E\u548C\u9884\u6D4B\u4ECE\u6574\u6570\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u3002\u6211\u4EEC\u5220\u9664\u6807\u7B7E\u4E3A "),A=o("code"),I=t("-100"),M=t(" \u6240\u6709\u503C \uFF0C\u7136\u540E\u5C06\u7ED3\u679C\u4F20\u9012\u7ED9 "),C=o("code"),N=t("metric.compute()"),K=t(" \u65B9\u6CD5\uFF1A"),X=f(),w(z.$$.fragment),W=f(),w(G.$$.fragment),Q=f(),Y=o("p"),V=t("\u4E0E\u6211\u4EEC\u7684\u6A21\u578B\u76F8\u6BD4\uFF0C\u60A8\u7684\u6A21\u578B\u505A\u5F97\u5982\u4F55\uFF1F\u5982\u679C\u60A8\u83B7\u5F97\u7C7B\u4F3C\u7684\u6570\u5B57\uFF0C\u90A3\u4E48\u60A8\u7684\u8BAD\u7EC3\u5C31\u662F\u6210\u529F\u7684\uFF01")},l(B){u=p(B,"P",{});var ee=i(u);j=a(ee,"\u5B83\u8FD4\u56DE\u5F88\u591A\u4FE1\u606F\uFF01\u6211\u4EEC\u83B7\u5F97\u6BCF\u4E2A\u5355\u72EC\u5B9E\u4F53\u4EE5\u53CA\u6574\u4F53\u7684\u51C6\u786E\u7387\u3001\u53EC\u56DE\u7387\u548C F1 \u5206\u6570\u3002\u5BF9\u4E8E\u6211\u4EEC\u7684\u5EA6\u91CF\u8BA1\u7B97\uFF0C\u6211\u4EEC\u5C06\u53EA\u4FDD\u7559\u603B\u5206\uFF0C\u4F46\u53EF\u4EE5\u968F\u610F\u8C03\u6574 "),d=p(ee,"CODE",{});var U=i(d);$=a(U,"compute_metrics()"),U.forEach(s),q=a(ee," \u51FD\u6570\u8FD4\u56DE\u60A8\u60F3\u8981\u67E5\u770B\u7684\u6240\u6709\u6307\u6807\u3002"),ee.forEach(s),v=m(B),b=p(B,"P",{});var Z=i(b);T=a(Z,"\u8FD9"),S=p(Z,"CODE",{});var L=i(S);R=a(L,"compute_metrics()"),L.forEach(s),H=a(Z," \u51FD\u6570\u9996\u5148\u91C7\u7528 logits \u7684 argmax \u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u9884\u6D4B\uFF08\u50CF\u5F80\u5E38\u4E00\u6837\uFF0Clogits \u548C\u6982\u7387\u7684\u987A\u5E8F\u76F8\u540C\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E0D\u9700\u8981\u5E94\u7528 softmax\uFF09\u3002\u7136\u540E\u6211\u4EEC\u5FC5\u987B\u5C06\u6807\u7B7E\u548C\u9884\u6D4B\u4ECE\u6574\u6570\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u3002\u6211\u4EEC\u5220\u9664\u6807\u7B7E\u4E3A "),A=p(Z,"CODE",{});var se=i(A);I=a(se,"-100"),se.forEach(s),M=a(Z," \u6240\u6709\u503C \uFF0C\u7136\u540E\u5C06\u7ED3\u679C\u4F20\u9012\u7ED9 "),C=p(Z,"CODE",{});var J=i(C);N=a(J,"metric.compute()"),J.forEach(s),K=a(Z," \u65B9\u6CD5\uFF1A"),Z.forEach(s),X=m(B),E(z.$$.fragment,B),W=m(B),E(G.$$.fragment,B),Q=m(B),Y=p(B,"P",{});var pe=i(Y);V=a(pe,"\u4E0E\u6211\u4EEC\u7684\u6A21\u578B\u76F8\u6BD4\uFF0C\u60A8\u7684\u6A21\u578B\u505A\u5F97\u5982\u4F55\uFF1F\u5982\u679C\u60A8\u83B7\u5F97\u7C7B\u4F3C\u7684\u6570\u5B57\uFF0C\u90A3\u4E48\u60A8\u7684\u8BAD\u7EC3\u5C31\u662F\u6210\u529F\u7684\uFF01"),pe.forEach(s)},m(B,ee){n(B,u,ee),l(u,j),l(u,d),l(d,$),l(u,q),n(B,v,ee),n(B,b,ee),l(b,T),l(b,S),l(S,R),l(b,H),l(b,A),l(A,I),l(b,M),l(b,C),l(C,N),l(b,K),n(B,X,ee),x(z,B,ee),n(B,W,ee),x(G,B,ee),n(B,Q,ee),n(B,Y,ee),l(Y,V),te=!0},i(B){te||(k(z.$$.fragment,B),k(G.$$.fragment,B),te=!0)},o(B){g(z.$$.fragment,B),g(G.$$.fragment,B),te=!1},d(B){B&&s(u),B&&s(v),B&&s(b),B&&s(X),y(z,B),B&&s(W),y(G,B),B&&s(Q),B&&s(Y)}}}function Kc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te,B,ee,U,Z;return z=new P({props:{code:`import numpy as np


def compute_metrics(eval_preds):
    logits, labels = eval_preds
    predictions = np.argmax(logits, axis=-1)

    # Remove ignored index (special tokens) and convert to labels
    true_labels = [[label_names[l] for l in label if l != -100] for label in labels]
    true_predictions = [
        [label_names[p] for (p, l) in zip(prediction, label) if l != -100]
        for prediction, label in zip(predictions, labels)
    ]
    all_metrics = metric.compute(predictions=true_predictions, references=true_labels)
    return {
        "precision": all_metrics["overall_precision"],
        "recall": all_metrics["overall_recall"],
        "f1": all_metrics["overall_f1"],
        "accuracy": all_metrics["overall_accuracy"],
    }`,highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_preds</span>):
    logits, labels = eval_preds
    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)

    <span class="hljs-comment"># Remove ignored index (special tokens) and convert to labels</span>
    true_labels = [[label_names[l] <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> label <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]
    true_predictions = [
        [label_names[p] <span class="hljs-keyword">for</span> (p, l) <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label) <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>]
        <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
    ]
    all_metrics = metric.compute(predictions=true_predictions, references=true_labels)
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;precision&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_precision&quot;</span>],
        <span class="hljs-string">&quot;recall&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_recall&quot;</span>],
        <span class="hljs-string">&quot;f1&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_f1&quot;</span>],
        <span class="hljs-string">&quot;accuracy&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_accuracy&quot;</span>],
    }`}}),{c(){u=o("p"),j=t("\u5B83\u8FD4\u56DE\u5F88\u591A\u4FE1\u606F\uFF01\u6211\u4EEC\u83B7\u5F97\u6BCF\u4E2A\u5355\u72EC\u5B9E\u4F53\u4EE5\u53CA\u6574\u4F53\u7684\u51C6\u786E\u7387\u3001\u53EC\u56DE\u7387\u548C F1 \u5206\u6570\u3002\u5BF9\u4E8E\u6211\u4EEC\u7684\u5EA6\u91CF\u8BA1\u7B97\uFF0C\u6211\u4EEC\u5C06\u53EA\u4FDD\u7559\u603B\u5206\uFF0C\u4F46\u53EF\u4EE5\u968F\u610F\u8C03\u6574 "),d=o("code"),$=t("compute_metrics()"),q=t(" \u51FD\u6570\u8FD4\u56DE\u60A8\u60F3\u8981\u67E5\u770B\u7684\u6240\u6709\u6307\u6807\u3002"),v=f(),b=o("p"),T=t("\u8FD9"),S=o("code"),R=t("compute_metrics()"),H=t(" \u51FD\u6570\u9996\u5148\u91C7\u7528 logits \u7684 argmax \u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u9884\u6D4B\uFF08\u50CF\u5F80\u5E38\u4E00\u6837\uFF0Clogits \u548C\u6982\u7387\u7684\u987A\u5E8F\u76F8\u540C\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E0D\u9700\u8981\u5E94\u7528 softmax\uFF09\u3002\u7136\u540E\u6211\u4EEC\u5FC5\u987B\u5C06\u6807\u7B7E\u548C\u9884\u6D4B\u4ECE\u6574\u6570\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u3002\u6211\u4EEC\u5220\u9664\u6807\u7B7E\u4E3A "),A=o("code"),I=t("-100"),M=t(" \u6240\u6709\u503C \uFF0C\u7136\u540E\u5C06\u7ED3\u679C\u4F20\u9012\u7ED9 "),C=o("code"),N=t("metric.compute()"),K=t(" \u65B9\u6CD5\uFF1A"),X=f(),w(z.$$.fragment),W=f(),G=o("p"),Q=t("\u73B0\u5728\u5DF2\u7ECF\u5B8C\u6210\u4E86\uFF0C\u6211\u4EEC\u51E0\u4E4E\u51C6\u5907\u597D\u5B9A\u4E49\u6211\u4EEC\u7684 "),Y=o("code"),V=t("Trainer"),te=t(" .\u6211\u4EEC\u53EA\u9700\u8981\u4E00\u4E2A "),B=o("code"),ee=t("model"),U=t(" \u5FAE\u8C03\uFF01")},l(L){u=p(L,"P",{});var se=i(u);j=a(se,"\u5B83\u8FD4\u56DE\u5F88\u591A\u4FE1\u606F\uFF01\u6211\u4EEC\u83B7\u5F97\u6BCF\u4E2A\u5355\u72EC\u5B9E\u4F53\u4EE5\u53CA\u6574\u4F53\u7684\u51C6\u786E\u7387\u3001\u53EC\u56DE\u7387\u548C F1 \u5206\u6570\u3002\u5BF9\u4E8E\u6211\u4EEC\u7684\u5EA6\u91CF\u8BA1\u7B97\uFF0C\u6211\u4EEC\u5C06\u53EA\u4FDD\u7559\u603B\u5206\uFF0C\u4F46\u53EF\u4EE5\u968F\u610F\u8C03\u6574 "),d=p(se,"CODE",{});var J=i(d);$=a(J,"compute_metrics()"),J.forEach(s),q=a(se," \u51FD\u6570\u8FD4\u56DE\u60A8\u60F3\u8981\u67E5\u770B\u7684\u6240\u6709\u6307\u6807\u3002"),se.forEach(s),v=m(L),b=p(L,"P",{});var pe=i(b);T=a(pe,"\u8FD9"),S=p(pe,"CODE",{});var fe=i(S);R=a(fe,"compute_metrics()"),fe.forEach(s),H=a(pe," \u51FD\u6570\u9996\u5148\u91C7\u7528 logits \u7684 argmax \u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u9884\u6D4B\uFF08\u50CF\u5F80\u5E38\u4E00\u6837\uFF0Clogits \u548C\u6982\u7387\u7684\u987A\u5E8F\u76F8\u540C\uFF0C\u56E0\u6B64\u6211\u4EEC\u4E0D\u9700\u8981\u5E94\u7528 softmax\uFF09\u3002\u7136\u540E\u6211\u4EEC\u5FC5\u987B\u5C06\u6807\u7B7E\u548C\u9884\u6D4B\u4ECE\u6574\u6570\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u3002\u6211\u4EEC\u5220\u9664\u6807\u7B7E\u4E3A "),A=p(pe,"CODE",{});var ie=i(A);I=a(ie,"-100"),ie.forEach(s),M=a(pe," \u6240\u6709\u503C \uFF0C\u7136\u540E\u5C06\u7ED3\u679C\u4F20\u9012\u7ED9 "),C=p(pe,"CODE",{});var Se=i(C);N=a(Se,"metric.compute()"),Se.forEach(s),K=a(pe," \u65B9\u6CD5\uFF1A"),pe.forEach(s),X=m(L),E(z.$$.fragment,L),W=m(L),G=p(L,"P",{});var re=i(G);Q=a(re,"\u73B0\u5728\u5DF2\u7ECF\u5B8C\u6210\u4E86\uFF0C\u6211\u4EEC\u51E0\u4E4E\u51C6\u5907\u597D\u5B9A\u4E49\u6211\u4EEC\u7684 "),Y=p(re,"CODE",{});var Ns=i(Y);V=a(Ns,"Trainer"),Ns.forEach(s),te=a(re," .\u6211\u4EEC\u53EA\u9700\u8981\u4E00\u4E2A "),B=p(re,"CODE",{});var js=i(B);ee=a(js,"model"),js.forEach(s),U=a(re," \u5FAE\u8C03\uFF01"),re.forEach(s)},m(L,se){n(L,u,se),l(u,j),l(u,d),l(d,$),l(u,q),n(L,v,se),n(L,b,se),l(b,T),l(b,S),l(S,R),l(b,H),l(b,A),l(A,I),l(b,M),l(b,C),l(C,N),l(b,K),n(L,X,se),x(z,L,se),n(L,W,se),n(L,G,se),l(G,Q),l(G,Y),l(Y,V),l(G,te),l(G,B),l(B,ee),l(G,U),Z=!0},i(L){Z||(k(z.$$.fragment,L),Z=!0)},o(L){g(z.$$.fragment,L),Z=!1},d(L){L&&s(u),L&&s(v),L&&s(b),L&&s(X),y(z,L),L&&s(W),L&&s(G)}}}function xc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te,B,ee,U,Z,L,se,J,pe,fe,ie,Se,re,Ns,js,ue,Be,Ls,ae,Dl,ke,je,_e,Lt,rl,de,Ft,gs,ge,Pl,Te,vs,nl,Ne,ws,ol,ve,Le,ce,Es,xs,lt,zl,De,cs,Fe,le,pl,es,Al,ss,ls,he,fs,il,cl,fl,ml,Il,ts,ul,be,_l,ms,tt,Rl,as,we,Me,ne,Fs,He,at,Ms,Ee,Hs,ys,Gs,Sl,Pe,Os,Us,rs,Bl,Cs,ns,dl,Ge,hl,xe,os,Ue,us,bl,ye,Nl,_s,_,D,Ws,$l,Xs,Zs,kl,qs,Ll,Ts,Ks,Mt,jl,Vs,Ht,Fl,We,Xe,ps,rt,Ze,Ke,Ys,is,Ml,Js,Oe,Gt,Qs,$e,gl,vl,el,nt,Ds,Hl,ot,Pr,zr,Ut,pt,tr,it,wl,ds,Ar,_a,da,Ir,ha,Rr,Gl,Wt,ct,ar,Ve,Sr,ba,Br,Ul,ft,Nr,Lr,mt,Fr,Mr,$a,sl,rr,Wl,Xl,ut,_t,ka,Ye,nr,hs,Hr,ja,ga,Gr,va,or,dt,wa,bs,Zl,Xt,$s,pr,El,Ur,Ea,Ps,ir,xl,ht,bt,Zt,Wr,xa,ze,$t,ya,Oa,Xr,cr,kt,Je,Ce,Ca,qa,Zr,Ta,jt,Kr,Da,gt,Vr,Pa,za,Yr,Jr,zs,Qr,Aa,fr,vt,Kt,wt,mr,As,Vt,Ia,ur,Et,Yt,Jt,en,Ra,Is,Sa,oe,_r,me,sn,Ba,Na,ln,La,Fa,tn,Ma,Ha,an,Ga,Ua,rn,Wa,Xa,nn,Qt,Za,on,dr,Kl,Rs,xt,ea,Qe,pn,yl,cn,fn,sa;return Q=new P({props:{code:`id2label = {i: label for i, label in enumerate(label_names)}
label2id = {v: k for k, v in id2label.items()}`,highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`}}),L=new P({props:{code:`from transformers import AutoModelForTokenClassification

model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForTokenClassification

model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`}}),Be=new P({props:{code:"model.config.num_labels",highlighted:"model.config.num_labels"}}),ae=new P({props:{code:"9",highlighted:'<span class="hljs-number">9</span>'}}),ke=new Dr({props:{warning:!0,$$slots:{default:[Vc]},$$scope:{ctx:F}}}),vs=new P({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()`}}),ve=new P({props:{code:"huggingface-cli login",highlighted:"huggingface-cli login"}}),cs=new P({props:{code:`from transformers import TrainingArguments

args = TrainingArguments(
    "bert-finetuned-ner",
    evaluation_strategy="epoch",
    save_strategy="epoch",
    learning_rate=2e-5,
    num_train_epochs=3,
    weight_decay=0.01,
    push_to_hub=True,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

args = TrainingArguments(
    <span class="hljs-string">&quot;bert-finetuned-ner&quot;</span>,
    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    num_train_epochs=<span class="hljs-number">3</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`}}),as=new Dr({props:{$$slots:{default:[Yc]},$$scope:{ctx:F}}}),Ee=new P({props:{code:`from transformers import Trainer

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

trainer = Trainer(
    model=model,
    args=args,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    tokenizer=tokenizer,
)
trainer.train()`}}),ns=new P({props:{code:'trainer.push_to_hub(commit_message="Training complete")',highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)'}}),os=new P({props:{code:"'https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed'",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>'}}),We=new P({props:{code:`from torch.utils.data import DataLoader

train_dataloader = DataLoader(
    tokenized_datasets["train"],
    shuffle=True,
    collate_fn=data_collator,
    batch_size=8,
)
eval_dataloader = DataLoader(
    tokenized_datasets["validation"], collate_fn=data_collator, batch_size=8
)`,highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

train_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)
eval_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], collate_fn=data_collator, batch_size=<span class="hljs-number">8</span>
)`}}),Ke=new P({props:{code:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`}}),el=new P({props:{code:`from torch.optim import AdamW

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

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`}}),pt=new P({props:{code:`from accelerate import Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`,highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`}}),it=new Dr({props:{$$slots:{default:[Jc]},$$scope:{ctx:F}}}),ct=new P({props:{code:`from transformers import get_scheduler

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

lr_scheduler = get_scheduler(
    "linear",
    optimizer=optimizer,
    num_warmup_steps=0,
    num_training_steps=num_training_steps,
)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

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

lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)`}}),sl=new P({props:{code:`from huggingface_hub import Repository, get_full_repo_name

model_name = "bert-finetuned-ner-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;bert-finetuned-ner-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`}}),Wl=new P({props:{code:"'sgugger/bert-finetuned-ner-accelerate'",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>'}}),Ye=new P({props:{code:`output_dir = "bert-finetuned-ner-accelerate"
repo = Repository(output_dir, clone_from=repo_name)`,highlighted:`output_dir = <span class="hljs-string">&quot;bert-finetuned-ner-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`}}),$s=new Uo({}),ht=new P({props:{code:`def postprocess(predictions, labels):
    predictions = predictions.detach().cpu().clone().numpy()
    labels = labels.detach().cpu().clone().numpy()

    # Remove ignored index (special tokens) and convert to labels
    true_labels = [[label_names[l] for l in label if l != -100] for label in labels]
    true_predictions = [
        [label_names[p] for (p, l) in zip(prediction, label) if l != -100]
        for prediction, label in zip(predictions, labels)
    ]
    return true_labels, true_predictions`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">postprocess</span>(<span class="hljs-params">predictions, labels</span>):
    predictions = predictions.detach().cpu().clone().numpy()
    labels = labels.detach().cpu().clone().numpy()

    <span class="hljs-comment"># Remove ignored index (special tokens) and convert to labels</span>
    true_labels = [[label_names[l] <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> label <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]
    true_predictions = [
        [label_names[p] <span class="hljs-keyword">for</span> (p, l) <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label) <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>]
        <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
    ]
    <span class="hljs-keyword">return</span> true_labels, true_predictions`}}),Et=new P({props:{code:`from tqdm.auto import tqdm
import torch

progress_bar = tqdm(range(num_training_steps))

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

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

    # Evaluation
    model.eval()
    for batch in eval_dataloader:
        with torch.no_grad():
            outputs = model(**batch)

        predictions = outputs.logits.argmax(dim=-1)
        labels = batch["labels"]

        # Necessary to pad predictions and labels for being gathered
        predictions = accelerator.pad_across_processes(predictions, dim=1, pad_index=-100)
        labels = accelerator.pad_across_processes(labels, dim=1, pad_index=-100)

        predictions_gathered = accelerator.gather(predictions)
        labels_gathered = accelerator.gather(labels)

        true_predictions, true_labels = postprocess(predictions_gathered, labels_gathered)
        metric.add_batch(predictions=true_predictions, references=true_labels)

    results = metric.compute()
    print(
        f"epoch {epoch}:",
        {
            key: results[f"overall_{key}"]
            for key in ["precision", "recall", "f1", "accuracy"]
        },
    )

    # Save and upload
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    if accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=f"Training in progress epoch {epoch}", blocking=False
        )`,highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch

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

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

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

    <span class="hljs-comment"># Evaluation</span>
    model.<span class="hljs-built_in">eval</span>()
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
        <span class="hljs-keyword">with</span> torch.no_grad():
            outputs = model(**batch)

        predictions = outputs.logits.argmax(dim=-<span class="hljs-number">1</span>)
        labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]

        <span class="hljs-comment"># Necessary to pad predictions and labels for being gathered</span>
        predictions = accelerator.pad_across_processes(predictions, dim=<span class="hljs-number">1</span>, pad_index=-<span class="hljs-number">100</span>)
        labels = accelerator.pad_across_processes(labels, dim=<span class="hljs-number">1</span>, pad_index=-<span class="hljs-number">100</span>)

        predictions_gathered = accelerator.gather(predictions)
        labels_gathered = accelerator.gather(labels)

        true_predictions, true_labels = postprocess(predictions_gathered, labels_gathered)
        metric.add_batch(predictions=true_predictions, references=true_labels)

    results = metric.compute()
    <span class="hljs-built_in">print</span>(
        <span class="hljs-string">f&quot;epoch <span class="hljs-subst">{epoch}</span>:&quot;</span>,
        {
            key: results[<span class="hljs-string">f&quot;overall_<span class="hljs-subst">{key}</span>&quot;</span>]
            <span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;precision&quot;</span>, <span class="hljs-string">&quot;recall&quot;</span>, <span class="hljs-string">&quot;f1&quot;</span>, <span class="hljs-string">&quot;accuracy&quot;</span>]
        },
    )

    <span class="hljs-comment"># Save and upload</span>
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    <span class="hljs-keyword">if</span> accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=<span class="hljs-string">f&quot;Training in progress epoch <span class="hljs-subst">{epoch}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
        )`}}),Is=new P({props:{code:`accelerator.wait_for_everyone()
unwrapped_model = accelerator.unwrap_model(model)
unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)`,highlighted:`accelerator.wait_for_everyone()
unwrapped_model = accelerator.unwrap_model(model)
unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)`}}),{c(){u=o("h3"),j=t("\u5B9A\u4E49\u6A21\u578B"),d=f(),$=o("p"),q=t("\u7531\u4E8E\u6211\u4EEC\u6B63\u5728\u7814\u7A76Token\u5206\u7C7B\u95EE\u9898\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4F7F\u7528 "),v=o("code"),b=t("AutoModelForTokenClassification"),T=t(" \u7C7B\u3002\u5B9A\u4E49\u8FD9\u4E2A\u6A21\u578B\u65F6\u8981\u8BB0\u4F4F\u7684\u4E3B\u8981\u4E8B\u60C5\u662F\u4F20\u9012\u4E00\u4E9B\u5173\u4E8E\u6211\u4EEC\u7684\u6807\u7B7E\u6570\u91CF\u7684\u4FE1\u606F\u3002\u6267\u884C\u6B64\u64CD\u4F5C\u7684\u6700\u7B80\u5355\u65B9\u6CD5\u662F\u5C06\u8BE5\u6570\u5B57\u4F20\u9012\u7ED9 "),S=o("code"),R=t("num_labels"),H=t(" \u53C2\u6570\uFF0C\u4F46\u662F\u5982\u679C\u6211\u4EEC\u60F3\u8981\u4E00\u4E2A\u5F88\u597D\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728\u672C\u8282\u5F00\u5934\u770B\u5230\u7684\u90A3\u6837\uFF0C\u6700\u597D\u8BBE\u7F6E\u6B63\u786E\u7684\u6807\u7B7E\u5BF9\u5E94\u5173\u7CFB\u3002"),A=f(),I=o("p"),M=t("\u5B83\u4EEC\u5E94\u8BE5\u7531\u4E24\u4E2A\u5B57\u5178\u8BBE\u7F6E\uFF0C "),C=o("code"),N=t("id2label"),K=t(" \u548C "),X=o("code"),z=t("label2id"),W=t(" \uFF0C\u5176\u4E2D\u5305\u542B\u4ECE ID \u5230\u6807\u7B7E\u7684\u6620\u5C04\uFF0C\u53CD\u4E4B\u4EA6\u7136\uFF1A"),G=f(),w(Q.$$.fragment),Y=f(),V=o("p"),te=t("\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4EEC\u4F20\u9012\u7ED9 "),B=o("code"),ee=t("AutoModelForTokenClassification.from_pretrained()"),U=t(" \u65B9\u6CD5\uFF0C\u5B83\u4EEC\u5C06\u5728\u6A21\u578B\u7684\u914D\u7F6E\u4E2D\u8BBE\u7F6E\uFF0C\u7136\u540E\u4FDD\u5B58\u5E76\u4E0A\u4F20\u5230Hub\uFF1A"),Z=f(),w(L.$$.fragment),se=f(),J=o("p"),pe=t("\u5C31\u50CF\u6211\u4EEC\u5728"),fe=o("a"),ie=t("\u7B2C\u4E09\u7AE0"),Se=t(",\u5B9A\u4E49\u6211\u4EEC\u7684 "),re=o("code"),Ns=t("AutoModelForSequenceClassification"),js=t(" \uFF0C\u521B\u5EFA\u6A21\u578B\u4F1A\u53D1\u51FA\u8B66\u544A\uFF0C\u63D0\u793A\u4E00\u4E9B\u6743\u91CD\u672A\u88AB\u4F7F\u7528\uFF08\u6765\u81EA\u9884\u8BAD\u7EC3\u5934\u7684\u6743\u91CD\uFF09\u548C\u4E00\u4E9B\u5176\u4ED6\u6743\u91CD\u88AB\u968F\u673A\u521D\u59CB\u5316\uFF08\u6765\u81EA\u65B0Token\u5206\u7C7B\u5934\u7684\u6743\u91CD\uFF09\uFF0C\u6211\u4EEC\u5C06\u8981\u8BAD\u7EC3\u8FD9\u4E2A\u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5728\u4E00\u5206\u949F\u5185\u5B8C\u6210\uFF0C\u4F46\u9996\u5148\u8BA9\u6211\u4EEC\u4ED4\u7EC6\u68C0\u67E5\u6211\u4EEC\u7684\u6A21\u578B\u662F\u5426\u5177\u6709\u6B63\u786E\u6570\u91CF\u7684\u6807\u7B7E\uFF1A"),ue=f(),w(Be.$$.fragment),Ls=f(),w(ae.$$.fragment),Dl=f(),w(ke.$$.fragment),je=f(),_e=o("h3"),Lt=t("\u5FAE\u8C03\u6A21\u578B"),rl=f(),de=o("p"),Ft=t("\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u597D\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u4E86\uFF01\u5728\u5B9A\u4E49\u6211\u4EEC\u7684 "),gs=o("code"),ge=t("Trainer"),Pl=t("\u4E4B\u524D\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u505A\u6700\u540E\u4E24\u4EF6\u4E8B\uFF1A\u767B\u5F55 Hugging Face \u5E76\u5B9A\u4E49\u6211\u4EEC\u7684\u8BAD\u7EC3\u53C2\u6570\u3002\u5982\u679C\u60A8\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u6709\u4E00\u4E2A\u65B9\u4FBF\u7684\u529F\u80FD\u53EF\u4EE5\u5E2E\u52A9\u60A8\uFF1A"),Te=f(),w(vs.$$.fragment),nl=f(),Ne=o("p"),ws=t("\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u8D26\u53F7\u548C\u5BC6\u7801\u3002\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),ol=f(),w(ve.$$.fragment),Le=f(),ce=o("p"),Es=t("Once this is done, we can define our "),xs=o("code"),lt=t("TrainingArguments"),zl=t(":"),De=f(),w(cs.$$.fragment),Fe=f(),le=o("p"),pl=t("\u60A8\u4E4B\u524D\u5DF2\u7ECF\u770B\u8FC7\u5176\u4E2D\u7684\u5927\u90E8\u5206\u5185\u5BB9\uFF1A\u6211\u4EEC\u8BBE\u7F6E\u4E86\u4E00\u4E9B\u8D85\u53C2\u6570\uFF08\u4F8B\u5982\u5B66\u4E60\u7387\u3001\u8981\u8BAD\u7EC3\u7684 epoch \u6570\u548C\u6743\u91CD\u8870\u51CF\uFF09\uFF0C\u7136\u540E\u6211\u4EEC\u6307\u5B9A "),es=o("code"),Al=t("push_to_hub=True"),ss=t(" \u8868\u660E\u6211\u4EEC\u60F3\u8981\u4FDD\u5B58\u6A21\u578B\u5E76\u5728\u6BCF\u4E2A\u65F6\u671F\u7ED3\u675F\u65F6\u5BF9\u5176\u8FDB\u884C\u8BC4\u4F30\uFF0C\u5E76\u4E14\u6211\u4EEC\u60F3\u8981\u5C06\u6211\u4EEC\u7684\u7ED3\u679C\u4E0A\u4F20\u5230\u6A21\u578B\u4E2D\u5FC3\u3002\u8BF7\u6CE8\u610F\uFF0C\u53EF\u4EE5\u4F7F\u7528hub_model_id\u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0(\u7279\u522B\u662F\uFF0C\u5FC5\u987B\u4F7F\u7528\u8FD9\u4E2A\u53C2\u6570\u6765\u63A8\u9001\u5230\u4E00\u4E2A\u7EC4\u7EC7)\u3002\u4F8B\u5982\uFF0C\u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230"),ls=o("a"),he=o("code"),fs=t("huggingface-course"),il=t(" organization"),cl=t(", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),fl=o("code"),ml=t("hub_model_id=huggingface-course/bert-finetuned-ner"),Il=t(" \u5230 "),ts=o("code"),ul=t("TrainingArguments"),be=t(" \u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u60A8\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u60A8\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D\uFF0C\u56E0\u6B64\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\u5B83\u5C06\u662F "),_l=o("code"),ms=t("sgugger/bert-finetuned-ner"),tt=t("\u3002"),Rl=f(),w(as.$$.fragment),we=f(),Me=o("p"),ne=t("\u6700\u540E\uFF0C\u6211\u4EEC\u53EA\u662F\u5C06\u6240\u6709\u5185\u5BB9\u4F20\u9012\u7ED9 "),Fs=o("code"),He=t("Trainer"),at=t(" \u5E76\u542F\u52A8\u8BAD\u7EC3\uFF1A"),Ms=f(),w(Ee.$$.fragment),Hs=f(),ys=o("p"),Gs=t("\u8BF7\u6CE8\u610F\uFF0C\u5F53\u8BAD\u7EC3\u53D1\u751F\u65F6\uFF0C\u6BCF\u6B21\u4FDD\u5B58\u6A21\u578B\u65F6\uFF08\u8FD9\u91CC\u662F\u6BCF\u4E2Aepooch\uFF09\uFF0C\u5B83\u90FD\u4F1A\u5728\u540E\u53F0\u4E0A\u4F20\u5230 Hub\u3002\u8FD9\u6837\uFF0C\u5982\u6709\u5FC5\u8981\uFF0C\u60A8\u5C06\u80FD\u591F\u5728\u53E6\u4E00\u53F0\u673A\u5668\u4E0A\u7EE7\u7EED\u60A8\u7684\u8BAD\u7EC3\u3002"),Sl=f(),Pe=o("p"),Os=t("\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u4F7F\u7528 "),Us=o("code"),rs=t("push_to_hub()"),Bl=t(" \u786E\u4FDD\u6211\u4EEC\u4E0A\u4F20\u6A21\u578B\u7684\u6700\u65B0\u7248\u672C"),Cs=f(),w(ns.$$.fragment),dl=f(),Ge=o("p"),hl=t("This command returns the URL of the commit it just did, if you want to inspect it:"),xe=f(),w(os.$$.fragment),Ue=f(),us=o("p"),bl=t("\u8FD9 "),ye=o("code"),Nl=t("Trainer"),_s=t(" \u8FD8\u521B\u5EFA\u4E86\u4E00\u5F20\u5305\u542B\u6240\u6709\u8BC4\u4F30\u7ED3\u679C\u7684\u6A21\u578B\u5361\u5E76\u4E0A\u4F20\u3002\u5728\u6B64\u9636\u6BB5\uFF0C\u60A8\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u4E2D\u5FC3\u4E0A\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\u6765\u6D4B\u8BD5\u60A8\u7684\u6A21\u578B\u5E76\u4E0E\u60A8\u7684\u670B\u53CB\u5206\u4EAB\u3002\u60A8\u5DF2\u6210\u529F\u5728Token\u5206\u7C7B\u4EFB\u52A1\u4E0A\u5FAE\u8C03\u6A21\u578B - \u606D\u559C\uFF01"),_=f(),D=o("p"),Ws=t("\u5982\u679C\u60A8\u60F3\u66F4\u6DF1\u5165\u5730\u4E86\u89E3\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u6211\u4EEC\u73B0\u5728\u5C06\u5411\u60A8\u5C55\u793A\u5982\u4F55\u4F7F\u7528 \u{1F917} Accelerate \u505A\u540C\u6837\u7684\u4E8B\u60C5\u3002"),$l=f(),Xs=o("h2"),Zs=t("\u81EA\u5B9A\u4E49\u8BAD\u7EC3\u5FAA\u73AF"),kl=f(),qs=o("p"),Ll=t("\u73B0\u5728\u8BA9\u6211\u4EEC\u770B\u4E00\u4E0B\u5B8C\u6574\u7684\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u8FD9\u6837\u60A8\u53EF\u4EE5\u8F7B\u677E\u5B9A\u4E49\u6240\u9700\u7684\u90E8\u5206\u3002\u5B83\u770B\u8D77\u6765\u5F88\u50CF\u6211\u4EEC\u5728"),Ts=o("a"),Ks=t("\u7B2C\u4E09\u7AE0"),Mt=t(", \u6240\u505A\u7684\uFF0C\u5BF9\u8BC4\u4F30\u8FDB\u884C\u4E86\u4E00\u4E9B\u66F4\u6539\u3002"),jl=f(),Vs=o("h3"),Ht=t("\u505A\u597D\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"),Fl=t("\n\u9996\u5148\u6211\u4EEC\u9700\u8981\u4E3A\u6211\u4EEC\u7684\u6570\u636E\u96C6\u6784\u5EFA `DataLoader` \u3002\u6211\u4EEC\u5C06\u91CD\u7528\u6211\u4EEC\u7684 `data_collator` \u4F5C\u4E3A\u4E00\u4E2A `collate_fn` \u5E76\u6253\u4E71\u8BAD\u7EC3\u96C6\uFF0C\u4F46\u4E0D\u6253\u4E71\u9A8C\u8BC1\u96C6\uFF1A\n\n	"),w(We.$$.fragment),Xe=f(),ps=o("p"),rt=t("\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u91CD\u65B0\u5B9E\u4F8B\u5316\u6211\u4EEC\u7684\u6A21\u578B\uFF0C\u4EE5\u786E\u4FDD\u6211\u4EEC\u4E0D\u4F1A\u4ECE\u4E4B\u524D\u7684\u8BAD\u7EC3\u7EE7\u7EED\u8BAD\u7EC3\uFF0C\u800C\u662F\u518D\u6B21\u4ECE BERT \u9884\u8BAD\u7EC3\u6A21\u578B\u5F00\u59CB\uFF1A"),Ze=f(),w(Ke.$$.fragment),Ys=f(),is=o("p"),Ml=t("\u7136\u540E\u6211\u4EEC\u5C06\u9700\u8981\u4E00\u4E2A\u4F18\u5316\u5668\u3002\u6211\u4EEC\u5C06\u4F7F\u7528\u7ECF\u5178 "),Js=o("code"),Oe=t("AdamW"),Gt=t(" \uFF0C\u8FD9\u5C31\u50CF "),Qs=o("code"),$e=t("Adam"),gl=t(" \uFF0C\u4F46\u5728\u5E94\u7528\u6743\u91CD\u8870\u51CF\u7684\u65B9\u5F0F\u4E0A\u8FDB\u884C\u4E86\u6539\u8FDB\uFF1A"),vl=f(),w(el.$$.fragment),nt=f(),Ds=o("p"),Hl=t("Once we have all those objects, we can send them to the "),ot=o("code"),Pr=t("accelerator.prepare()"),zr=t(" method:"),Ut=f(),w(pt.$$.fragment),tr=f(),w(it.$$.fragment),wl=f(),ds=o("p"),Ar=t("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u53D1\u9001\u4E86\u6211\u4EEC\u7684 "),_a=o("code"),da=t("train_dataloader"),Ir=t(" \u5230 "),ha=o("code"),Rr=t("accelerator.prepare()"),Gl=t(" \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"),Wt=f(),w(ct.$$.fragment),ar=f(),Ve=o("p"),Sr=t("\u6700\u540E\uFF0C\u8981\u5C06\u6211\u4EEC\u7684\u6A21\u578B\u63A8\u9001\u5230 Hub\uFF0C\u6211\u4EEC\u9700\u8981\u521B\u5EFA\u4E00\u4E2A "),ba=o("code"),Br=t("Repository"),Ul=t(" \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 "),ft=o("code"),Nr=t("repo_name"),Lr=t(" \uFF1B\u5B83\u53EA\u9700\u8981\u5305\u542B\u60A8\u7684\u7528\u6237\u540D\uFF0C\u53EF\u4EE5\u4F7F\u7528"),mt=o("code"),Fr=t("get_full_repo_name()"),Mr=t("\u51FD\u6570\u7684\u67E5\u770B\u76EE\u524D\u7684repo_name\uFF09\uFF1A"),$a=f(),w(sl.$$.fragment),rr=f(),w(Wl.$$.fragment),Xl=f(),ut=o("p"),_t=t("Then we can clone that repository in a local folder. If it already exists, this local folder should be an existing clone of the repository we are working with:"),ka=f(),w(Ye.$$.fragment),nr=f(),hs=o("p"),Hr=t("We can now upload anything we save in "),ja=o("code"),ga=t("output_dir"),Gr=t(" by calling the "),va=o("code"),or=t("repo.push_to_hub()"),dt=t(" method. This will help us upload the intermediate models at the end of each epoch."),wa=f(),bs=o("h3"),Zl=o("a"),Xt=o("span"),w($s.$$.fragment),pr=f(),El=o("span"),Ur=t("Training loop"),Ea=f(),Ps=o("h3"),ir=t("\u8BAD\u7EC3\u5FAA\u73AF"),xl=t("\n\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u7F16\u5199\u5B8C\u6574\u7684\u8BAD\u7EC3\u5FAA\u73AF\u3002\u4E3A\u4E86\u7B80\u5316\u5B83\u7684\u8BC4\u4F30\u90E8\u5206\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E86\u8FD9\u4E2A `postprocess()` \u63A5\u53D7\u9884\u6D4B\u548C\u6807\u7B7E\u5E76\u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u5217\u8868\u7684\u51FD\u6570\uFF0C\u4E5F\u5C31\u662F `metric`\u5BF9\u8C61\u9700\u8981\u7684\u8F93\u5165\u683C\u5F0F\uFF1A\n\n	"),w(ht.$$.fragment),bt=f(),Zt=o("p"),Wr=t("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7F16\u5199\u8BAD\u7EC3\u5FAA\u73AF\u3002\u5728\u5B9A\u4E49\u4E00\u4E2A\u8FDB\u5EA6\u6761\u6765\u8DDF\u8E2A\u8BAD\u7EC3\u7684\u8FDB\u884C\u540E\uFF0C\u5FAA\u73AF\u5206\u4E3A\u4E09\u4E2A\u90E8\u5206\uFF1A"),xa=f(),ze=o("ul"),$t=o("li"),ya=t("\u8BAD\u7EC3\u672C\u8EAB\uFF0C\u8FD9\u662F\u5BF9"),Oa=o("code"),Xr=t("train_dataloader"),cr=t("\u7684\u7ECF\u5178\u8FED\u4EE3\uFF0C\u5411\u524D\u4F20\u9012\u6A21\u578B\uFF0C\u7136\u540E\u53CD\u5411\u4F20\u9012\u548C\u4F18\u5316\u53C2\u6570"),kt=f(),Je=o("li"),Ce=t("\u8BC4\u4F30,\u5728\u83B7\u5F97\u6211\u4EEC\u6A21\u578B\u7684\u8F93\u51FA\u540E:\u56E0\u4E3A\u4E24\u4E2A\u8FDB\u7A0B\u53EF\u80FD\u5C06\u8F93\u5165\u548C\u6807\u7B7E\u586B\u5145\u6210\u4E0D\u540C\u7684\u5F62\u72B6,\u5728\u8C03\u7528"),Ca=o("code"),qa=t("gather()"),Zr=t("\u65B9\u6CD5\u524D\u6211\u4EEC\u9700\u8981\u4F7F\u7528"),Ta=o("code"),jt=t("accelerator.pad_across_processes()"),Kr=t("\u6765\u8BA9\u9884\u6D4B\u548C\u6807\u7B7E\u5F62\u72B6\u76F8\u540C\u3002\u5982\u679C\u6211\u4EEC\u4E0D\u8FD9\u6837\u505A\uFF0C\u8BC4\u4F30\u8981\u4E48\u51FA\u9519\uFF0C\u8981\u4E48\u6C38\u8FDC\u4E0D\u4F1A\u5F97\u5230\u7ED3\u679C\u3002\u7136\u540E\uFF0C\u6211\u4EEC\u5C06\u7ED3\u679C\u53D1\u9001\u7ED9"),Da=o("code"),gt=t("metric.add_batch()"),Vr=t("\uFF0C\u5E76\u5728\u8BA1\u7B97\u5FAA\u73AF\u7ED3\u675F\u540E\u8C03\u7528"),Pa=o("code"),za=t("metric.compute()"),Yr=t("\u3002"),Jr=f(),zs=o("li"),Qr=t("\u4FDD\u5B58\u548C\u4E0A\u4F20\uFF0C\u9996\u5148\u4FDD\u5B58\u6A21\u578B\u548C\u6807\u8BB0\u5668\uFF0C\u7136\u540E\u8C03\u7528"),Aa=o("code"),fr=t("repo.push_to_hub()"),vt=t("\u3002\u6CE8\u610F\uFF0C\u6211\u4EEC\u4F7F\u7528\u53C2\u6570"),Kt=o("code"),wt=t("blocking=False"),mr=t("\u544A\u8BC9\u{1F917} hub \u5E93\u7528\u5728\u5F02\u6B65\u8FDB\u7A0B\u4E2D\u63A8\u9001\u3002\u8FD9\u6837\uFF0C\u8BAD\u7EC3\u5C06\u6B63\u5E38\u7EE7\u7EED\uFF0C\u5E76\u4E14\u8BE5\uFF08\u957F\uFF09\u6307\u4EE4\u5C06\u5728\u540E\u53F0\u6267\u884C\u3002"),As=f(),Vt=o("p"),Ia=t("\u8FD9\u662F\u8BAD\u7EC3\u5FAA\u73AF\u7684\u5B8C\u6574\u4EE3\u7801\uFF1A"),ur=f(),w(Et.$$.fragment),Yt=f(),Jt=o("p"),en=t("\u679C\u8FD9\u662F\u60A8\u7B2C\u4E00\u6B21\u770B\u5230\u7528 \u{1F917} Accelerate \u4FDD\u5B58\u7684\u6A21\u578B\uFF0C\u8BA9\u6211\u4EEC\u82B1\u70B9\u65F6\u95F4\u68C0\u67E5\u4E00\u4E0B\u5B83\u9644\u5E26\u7684\u4E09\u884C\u4EE3\u7801\uFF1A"),Ra=f(),w(Is.$$.fragment),Sa=f(),oe=o("p"),_r=t("\u7B2C\u4E00\u884C\u662F\u4E0D\u8A00\u81EA\u660E\u7684\uFF1A\u5B83\u544A\u8BC9\u6240\u6709\u8FDB\u7A0B\u7B49\u5230\u90FD\u5904\u4E8E\u90A3\u4E2A\u9636\u6BB5\u518D\u7EE7\u7EED(\u963B\u585E)\u3002\u8FD9\u662F\u4E3A\u4E86\u786E\u4FDD\u5728\u4FDD\u5B58\u4E4B\u524D\uFF0C\u6211\u4EEC\u5728\u6BCF\u4E2A\u8FC7\u7A0B\u4E2D\u90FD\u6709\u76F8\u540C\u7684\u6A21\u578B\u3002\u7136\u540E\u83B7\u53D6"),me=o("code"),sn=t("unwrapped_model"),Ba=t(`\uFF0C\u5B83\u662F\u6211\u4EEC\u5B9A\u4E49\u7684\u57FA\u672C\u6A21\u578B\u3002
`),Na=o("code"),ln=t("accelerator.prepare()"),La=t("\u65B9\u6CD5\u5C06\u6A21\u578B\u66F4\u6539\u4E3A\u5728\u5206\u5E03\u5F0F\u8BAD\u7EC3\u4E2D\u5DE5\u4F5C\uFF0C\u6240\u4EE5\u5B83\u4E0D\u518D\u6709"),Fa=o("code"),tn=t("save_pretraining()"),Ma=t("\u65B9\u6CD5;"),Ha=o("code"),an=t("accelerator.unwrap_model()"),Ga=t("\u65B9\u6CD5\u5C06\u64A4\u9500\u8BE5\u6B65\u9AA4\u3002\u6700\u540E\uFF0C\u6211\u4EEC\u8C03\u7528"),Ua=o("code"),rn=t("save_pretraining()"),Wa=t("\uFF0C\u4F46\u544A\u8BC9\u8BE5\u65B9\u6CD5\u4F7F\u7528"),Xa=o("code"),nn=t("accelerator.save()"),Qt=t("\u800C\u4E0D\u662F"),Za=o("code"),on=t("torch.save()"),dr=t("\u3002"),Kl=f(),Rs=o("p"),xt=t("\u5F53\u5B8C\u6210\u4E4B\u540E\uFF0C\u4F60\u5E94\u8BE5\u6709\u4E00\u4E2A\u6A21\u578B\uFF0C\u5B83\u4EA7\u751F\u7684\u7ED3\u679C\u4E0E"),ea=o("code"),Qe=t("Trainer"),pn=t("\u7684\u7ED3\u679C\u975E\u5E38\u76F8\u4F3C\u3002\u4F60\u53EF\u4EE5\u5728"),yl=o("a"),cn=t("hugs face-course/bert-fine - tuning -ner-accelerate"),fn=t("\u4E2D\u67E5\u770B\u6211\u4EEC\u4F7F\u7528\u8FD9\u4E2A\u4EE3\u7801\u8BAD\u7EC3\u7684\u6A21\u578B\u3002\u5982\u679C\u4F60\u60F3\u6D4B\u8BD5\u8BAD\u7EC3\u5FAA\u73AF\u7684\u4EFB\u4F55\u8C03\u6574\uFF0C\u4F60\u53EF\u4EE5\u76F4\u63A5\u901A\u8FC7\u7F16\u8F91\u4E0A\u9762\u663E\u793A\u7684\u4EE3\u7801\u6765\u5B9E\u73B0\u5B83\u4EEC!"),this.h()},l(r){u=p(r,"H3",{id:!0});var h=i(u);j=a(h,"\u5B9A\u4E49\u6A21\u578B"),h.forEach(s),d=m(r),$=p(r,"P",{});var Vl=i($);q=a(Vl,"\u7531\u4E8E\u6211\u4EEC\u6B63\u5728\u7814\u7A76Token\u5206\u7C7B\u95EE\u9898\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4F7F\u7528 "),v=p(Vl,"CODE",{});var Fn=i(v);b=a(Fn,"AutoModelForTokenClassification"),Fn.forEach(s),T=a(Vl," \u7C7B\u3002\u5B9A\u4E49\u8FD9\u4E2A\u6A21\u578B\u65F6\u8981\u8BB0\u4F4F\u7684\u4E3B\u8981\u4E8B\u60C5\u662F\u4F20\u9012\u4E00\u4E9B\u5173\u4E8E\u6211\u4EEC\u7684\u6807\u7B7E\u6570\u91CF\u7684\u4FE1\u606F\u3002\u6267\u884C\u6B64\u64CD\u4F5C\u7684\u6700\u7B80\u5355\u65B9\u6CD5\u662F\u5C06\u8BE5\u6570\u5B57\u4F20\u9012\u7ED9 "),S=p(Vl,"CODE",{});var Mn=i(S);R=a(Mn,"num_labels"),Mn.forEach(s),H=a(Vl," \u53C2\u6570\uFF0C\u4F46\u662F\u5982\u679C\u6211\u4EEC\u60F3\u8981\u4E00\u4E2A\u5F88\u597D\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\uFF0C\u5C31\u50CF\u6211\u4EEC\u5728\u672C\u8282\u5F00\u5934\u770B\u5230\u7684\u90A3\u6837\uFF0C\u6700\u597D\u8BBE\u7F6E\u6B63\u786E\u7684\u6807\u7B7E\u5BF9\u5E94\u5173\u7CFB\u3002"),Vl.forEach(s),A=m(r),I=p(r,"P",{});var Yl=i(I);M=a(Yl,"\u5B83\u4EEC\u5E94\u8BE5\u7531\u4E24\u4E2A\u5B57\u5178\u8BBE\u7F6E\uFF0C "),C=p(Yl,"CODE",{});var Hn=i(C);N=a(Hn,"id2label"),Hn.forEach(s),K=a(Yl," \u548C "),X=p(Yl,"CODE",{});var Gn=i(X);z=a(Gn,"label2id"),Gn.forEach(s),W=a(Yl," \uFF0C\u5176\u4E2D\u5305\u542B\u4ECE ID \u5230\u6807\u7B7E\u7684\u6620\u5C04\uFF0C\u53CD\u4E4B\u4EA6\u7136\uFF1A"),Yl.forEach(s),G=m(r),E(Q.$$.fragment,r),Y=m(r),V=p(r,"P",{});var Ka=i(V);te=a(Ka,"\u73B0\u5728\u6211\u4EEC\u53EF\u4EE5\u5C06\u5B83\u4EEC\u4F20\u9012\u7ED9 "),B=p(Ka,"CODE",{});var la=i(B);ee=a(la,"AutoModelForTokenClassification.from_pretrained()"),la.forEach(s),U=a(Ka," \u65B9\u6CD5\uFF0C\u5B83\u4EEC\u5C06\u5728\u6A21\u578B\u7684\u914D\u7F6E\u4E2D\u8BBE\u7F6E\uFF0C\u7136\u540E\u4FDD\u5B58\u5E76\u4E0A\u4F20\u5230Hub\uFF1A"),Ka.forEach(s),Z=m(r),E(L.$$.fragment,r),se=m(r),J=p(r,"P",{});var yt=i(J);pe=a(yt,"\u5C31\u50CF\u6211\u4EEC\u5728"),fe=p(yt,"A",{href:!0});var Va=i(fe);ie=a(Va,"\u7B2C\u4E09\u7AE0"),Va.forEach(s),Se=a(yt,",\u5B9A\u4E49\u6211\u4EEC\u7684 "),re=p(yt,"CODE",{});var Un=i(re);Ns=a(Un,"AutoModelForSequenceClassification"),Un.forEach(s),js=a(yt," \uFF0C\u521B\u5EFA\u6A21\u578B\u4F1A\u53D1\u51FA\u8B66\u544A\uFF0C\u63D0\u793A\u4E00\u4E9B\u6743\u91CD\u672A\u88AB\u4F7F\u7528\uFF08\u6765\u81EA\u9884\u8BAD\u7EC3\u5934\u7684\u6743\u91CD\uFF09\u548C\u4E00\u4E9B\u5176\u4ED6\u6743\u91CD\u88AB\u968F\u673A\u521D\u59CB\u5316\uFF08\u6765\u81EA\u65B0Token\u5206\u7C7B\u5934\u7684\u6743\u91CD\uFF09\uFF0C\u6211\u4EEC\u5C06\u8981\u8BAD\u7EC3\u8FD9\u4E2A\u6A21\u578B\u3002\u6211\u4EEC\u5C06\u5728\u4E00\u5206\u949F\u5185\u5B8C\u6210\uFF0C\u4F46\u9996\u5148\u8BA9\u6211\u4EEC\u4ED4\u7EC6\u68C0\u67E5\u6211\u4EEC\u7684\u6A21\u578B\u662F\u5426\u5177\u6709\u6B63\u786E\u6570\u91CF\u7684\u6807\u7B7E\uFF1A"),yt.forEach(s),ue=m(r),E(Be.$$.fragment,r),Ls=m(r),E(ae.$$.fragment,r),Dl=m(r),E(ke.$$.fragment,r),je=m(r),_e=p(r,"H3",{id:!0});var mn=i(_e);Lt=a(mn,"\u5FAE\u8C03\u6A21\u578B"),mn.forEach(s),rl=m(r),de=p(r,"P",{});var Jl=i(de);Ft=a(Jl,"\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u597D\u8BAD\u7EC3\u6211\u4EEC\u7684\u6A21\u578B\u4E86\uFF01\u5728\u5B9A\u4E49\u6211\u4EEC\u7684 "),gs=p(Jl,"CODE",{});var un=i(gs);ge=a(un,"Trainer"),un.forEach(s),Pl=a(Jl,"\u4E4B\u524D\uFF0C\u6211\u4EEC\u53EA\u9700\u8981\u505A\u6700\u540E\u4E24\u4EF6\u4E8B\uFF1A\u767B\u5F55 Hugging Face \u5E76\u5B9A\u4E49\u6211\u4EEC\u7684\u8BAD\u7EC3\u53C2\u6570\u3002\u5982\u679C\u60A8\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u6709\u4E00\u4E2A\u65B9\u4FBF\u7684\u529F\u80FD\u53EF\u4EE5\u5E2E\u52A9\u60A8\uFF1A"),Jl.forEach(s),Te=m(r),E(vs.$$.fragment,r),nl=m(r),Ne=p(r,"P",{});var ta=i(Ne);ws=a(ta,"\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6\uFF0C\u60A8\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u60A8\u7684 Hugging Face \u8D26\u53F7\u548C\u5BC6\u7801\u3002\u5982\u679C\u60A8\u4E0D\u662F\u5728notebook\u4E0A\u5DE5\u4F5C\uFF0C\u53EA\u9700\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u4EE5\u4E0B\u884C\uFF1A"),ta.forEach(s),ol=m(r),E(ve.$$.fragment,r),Le=m(r),ce=p(r,"P",{});var Ya=i(ce);Es=a(Ya,"Once this is done, we can define our "),xs=p(Ya,"CODE",{});var Ol=i(xs);lt=a(Ol,"TrainingArguments"),Ol.forEach(s),zl=a(Ya,":"),Ya.forEach(s),De=m(r),E(cs.$$.fragment,r),Fe=m(r),le=p(r,"P",{});var ks=i(le);pl=a(ks,"\u60A8\u4E4B\u524D\u5DF2\u7ECF\u770B\u8FC7\u5176\u4E2D\u7684\u5927\u90E8\u5206\u5185\u5BB9\uFF1A\u6211\u4EEC\u8BBE\u7F6E\u4E86\u4E00\u4E9B\u8D85\u53C2\u6570\uFF08\u4F8B\u5982\u5B66\u4E60\u7387\u3001\u8981\u8BAD\u7EC3\u7684 epoch \u6570\u548C\u6743\u91CD\u8870\u51CF\uFF09\uFF0C\u7136\u540E\u6211\u4EEC\u6307\u5B9A "),es=p(ks,"CODE",{});var hr=i(es);Al=a(hr,"push_to_hub=True"),hr.forEach(s),ss=a(ks," \u8868\u660E\u6211\u4EEC\u60F3\u8981\u4FDD\u5B58\u6A21\u578B\u5E76\u5728\u6BCF\u4E2A\u65F6\u671F\u7ED3\u675F\u65F6\u5BF9\u5176\u8FDB\u884C\u8BC4\u4F30\uFF0C\u5E76\u4E14\u6211\u4EEC\u60F3\u8981\u5C06\u6211\u4EEC\u7684\u7ED3\u679C\u4E0A\u4F20\u5230\u6A21\u578B\u4E2D\u5FC3\u3002\u8BF7\u6CE8\u610F\uFF0C\u53EF\u4EE5\u4F7F\u7528hub_model_id\u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0(\u7279\u522B\u662F\uFF0C\u5FC5\u987B\u4F7F\u7528\u8FD9\u4E2A\u53C2\u6570\u6765\u63A8\u9001\u5230\u4E00\u4E2A\u7EC4\u7EC7)\u3002\u4F8B\u5982\uFF0C\u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230"),ls=p(ks,"A",{href:!0,rel:!0});var _n=i(ls);he=p(_n,"CODE",{});var Wn=i(he);fs=a(Wn,"huggingface-course"),Wn.forEach(s),il=a(_n," organization"),_n.forEach(s),cl=a(ks,", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),fl=p(ks,"CODE",{});var br=i(fl);ml=a(br,"hub_model_id=huggingface-course/bert-finetuned-ner"),br.forEach(s),Il=a(ks," \u5230 "),ts=p(ks,"CODE",{});var Xn=i(ts);ul=a(Xn,"TrainingArguments"),Xn.forEach(s),be=a(ks," \u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C\u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u60A8\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u60A8\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D\uFF0C\u56E0\u6B64\u5728\u6211\u4EEC\u7684\u4F8B\u5B50\u4E2D\u5B83\u5C06\u662F "),_l=p(ks,"CODE",{});var Zn=i(_l);ms=a(Zn,"sgugger/bert-finetuned-ner"),Zn.forEach(s),tt=a(ks,"\u3002"),ks.forEach(s),Rl=m(r),E(as.$$.fragment,r),we=m(r),Me=p(r,"P",{});var Ja=i(Me);ne=a(Ja,"\u6700\u540E\uFF0C\u6211\u4EEC\u53EA\u662F\u5C06\u6240\u6709\u5185\u5BB9\u4F20\u9012\u7ED9 "),Fs=p(Ja,"CODE",{});var Ot=i(Fs);He=a(Ot,"Trainer"),Ot.forEach(s),at=a(Ja," \u5E76\u542F\u52A8\u8BAD\u7EC3\uFF1A"),Ja.forEach(s),Ms=m(r),E(Ee.$$.fragment,r),Hs=m(r),ys=p(r,"P",{});var dn=i(ys);Gs=a(dn,"\u8BF7\u6CE8\u610F\uFF0C\u5F53\u8BAD\u7EC3\u53D1\u751F\u65F6\uFF0C\u6BCF\u6B21\u4FDD\u5B58\u6A21\u578B\u65F6\uFF08\u8FD9\u91CC\u662F\u6BCF\u4E2Aepooch\uFF09\uFF0C\u5B83\u90FD\u4F1A\u5728\u540E\u53F0\u4E0A\u4F20\u5230 Hub\u3002\u8FD9\u6837\uFF0C\u5982\u6709\u5FC5\u8981\uFF0C\u60A8\u5C06\u80FD\u591F\u5728\u53E6\u4E00\u53F0\u673A\u5668\u4E0A\u7EE7\u7EED\u60A8\u7684\u8BAD\u7EC3\u3002"),dn.forEach(s),Sl=m(r),Pe=p(r,"P",{});var Ae=i(Pe);Os=a(Ae,"\u8BAD\u7EC3\u5B8C\u6210\u540E\uFF0C\u6211\u4EEC\u4F7F\u7528 "),Us=p(Ae,"CODE",{});var Kn=i(Us);rs=a(Kn,"push_to_hub()"),Kn.forEach(s),Bl=a(Ae," \u786E\u4FDD\u6211\u4EEC\u4E0A\u4F20\u6A21\u578B\u7684\u6700\u65B0\u7248\u672C"),Ae.forEach(s),Cs=m(r),E(ns.$$.fragment,r),dl=m(r),Ge=p(r,"P",{});var $r=i(Ge);hl=a($r,"This command returns the URL of the commit it just did, if you want to inspect it:"),$r.forEach(s),xe=m(r),E(os.$$.fragment,r),Ue=m(r),us=p(r,"P",{});var kr=i(us);bl=a(kr,"\u8FD9 "),ye=p(kr,"CODE",{});var Vn=i(ye);Nl=a(Vn,"Trainer"),Vn.forEach(s),_s=a(kr," \u8FD8\u521B\u5EFA\u4E86\u4E00\u5F20\u5305\u542B\u6240\u6709\u8BC4\u4F30\u7ED3\u679C\u7684\u6A21\u578B\u5361\u5E76\u4E0A\u4F20\u3002\u5728\u6B64\u9636\u6BB5\uFF0C\u60A8\u53EF\u4EE5\u4F7F\u7528\u6A21\u578B\u4E2D\u5FC3\u4E0A\u7684\u63A8\u7406\u5C0F\u90E8\u4EF6\u6765\u6D4B\u8BD5\u60A8\u7684\u6A21\u578B\u5E76\u4E0E\u60A8\u7684\u670B\u53CB\u5206\u4EAB\u3002\u60A8\u5DF2\u6210\u529F\u5728Token\u5206\u7C7B\u4EFB\u52A1\u4E0A\u5FAE\u8C03\u6A21\u578B - \u606D\u559C\uFF01"),kr.forEach(s),_=m(r),D=p(r,"P",{});var jr=i(D);Ws=a(jr,"\u5982\u679C\u60A8\u60F3\u66F4\u6DF1\u5165\u5730\u4E86\u89E3\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u6211\u4EEC\u73B0\u5728\u5C06\u5411\u60A8\u5C55\u793A\u5982\u4F55\u4F7F\u7528 \u{1F917} Accelerate \u505A\u540C\u6837\u7684\u4E8B\u60C5\u3002"),jr.forEach(s),$l=m(r),Xs=p(r,"H2",{id:!0});var Yn=i(Xs);Zs=a(Yn,"\u81EA\u5B9A\u4E49\u8BAD\u7EC3\u5FAA\u73AF"),Yn.forEach(s),kl=m(r),qs=p(r,"P",{});var gr=i(qs);Ll=a(gr,"\u73B0\u5728\u8BA9\u6211\u4EEC\u770B\u4E00\u4E0B\u5B8C\u6574\u7684\u8BAD\u7EC3\u5FAA\u73AF\uFF0C\u8FD9\u6837\u60A8\u53EF\u4EE5\u8F7B\u677E\u5B9A\u4E49\u6240\u9700\u7684\u90E8\u5206\u3002\u5B83\u770B\u8D77\u6765\u5F88\u50CF\u6211\u4EEC\u5728"),Ts=p(gr,"A",{href:!0});var vr=i(Ts);Ks=a(vr,"\u7B2C\u4E09\u7AE0"),vr.forEach(s),Mt=a(gr,", \u6240\u505A\u7684\uFF0C\u5BF9\u8BC4\u4F30\u8FDB\u884C\u4E86\u4E00\u4E9B\u66F4\u6539\u3002"),gr.forEach(s),jl=m(r),Vs=p(r,"H3",{id:!0});var Jn=i(Vs);Ht=a(Jn,"\u505A\u597D\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"),Jn.forEach(s),Fl=a(r,"\n\u9996\u5148\u6211\u4EEC\u9700\u8981\u4E3A\u6211\u4EEC\u7684\u6570\u636E\u96C6\u6784\u5EFA `DataLoader` \u3002\u6211\u4EEC\u5C06\u91CD\u7528\u6211\u4EEC\u7684 `data_collator` \u4F5C\u4E3A\u4E00\u4E2A `collate_fn` \u5E76\u6253\u4E71\u8BAD\u7EC3\u96C6\uFF0C\u4F46\u4E0D\u6253\u4E71\u9A8C\u8BC1\u96C6\uFF1A\n\n	"),E(We.$$.fragment,r),Xe=m(r),ps=p(r,"P",{});var Qn=i(ps);rt=a(Qn,"\u63A5\u4E0B\u6765\uFF0C\u6211\u4EEC\u91CD\u65B0\u5B9E\u4F8B\u5316\u6211\u4EEC\u7684\u6A21\u578B\uFF0C\u4EE5\u786E\u4FDD\u6211\u4EEC\u4E0D\u4F1A\u4ECE\u4E4B\u524D\u7684\u8BAD\u7EC3\u7EE7\u7EED\u8BAD\u7EC3\uFF0C\u800C\u662F\u518D\u6B21\u4ECE BERT \u9884\u8BAD\u7EC3\u6A21\u578B\u5F00\u59CB\uFF1A"),Qn.forEach(s),Ze=m(r),E(Ke.$$.fragment,r),Ys=m(r),is=p(r,"P",{});var Ql=i(is);Ml=a(Ql,"\u7136\u540E\u6211\u4EEC\u5C06\u9700\u8981\u4E00\u4E2A\u4F18\u5316\u5668\u3002\u6211\u4EEC\u5C06\u4F7F\u7528\u7ECF\u5178 "),Js=p(Ql,"CODE",{});var eo=i(Js);Oe=a(eo,"AdamW"),eo.forEach(s),Gt=a(Ql," \uFF0C\u8FD9\u5C31\u50CF "),Qs=p(Ql,"CODE",{});var so=i(Qs);$e=a(so,"Adam"),so.forEach(s),gl=a(Ql," \uFF0C\u4F46\u5728\u5E94\u7528\u6743\u91CD\u8870\u51CF\u7684\u65B9\u5F0F\u4E0A\u8FDB\u884C\u4E86\u6539\u8FDB\uFF1A"),Ql.forEach(s),vl=m(r),E(el.$$.fragment,r),nt=m(r),Ds=p(r,"P",{});var Qa=i(Ds);Hl=a(Qa,"Once we have all those objects, we can send them to the "),ot=p(Qa,"CODE",{});var aa=i(ot);Pr=a(aa,"accelerator.prepare()"),aa.forEach(s),zr=a(Qa," method:"),Qa.forEach(s),Ut=m(r),E(pt.$$.fragment,r),tr=m(r),E(it.$$.fragment,r),wl=m(r),ds=p(r,"P",{});var Ct=i(ds);Ar=a(Ct,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u53D1\u9001\u4E86\u6211\u4EEC\u7684 "),_a=p(Ct,"CODE",{});var er=i(_a);da=a(er,"train_dataloader"),er.forEach(s),Ir=a(Ct," \u5230 "),ha=p(Ct,"CODE",{});var lo=i(ha);Rr=a(lo,"accelerator.prepare()"),lo.forEach(s),Gl=a(Ct," \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.forEach(s),Wt=m(r),E(ct.$$.fragment,r),ar=m(r),Ve=p(r,"P",{});var Cl=i(Ve);Sr=a(Cl,"\u6700\u540E\uFF0C\u8981\u5C06\u6211\u4EEC\u7684\u6A21\u578B\u63A8\u9001\u5230 Hub\uFF0C\u6211\u4EEC\u9700\u8981\u521B\u5EFA\u4E00\u4E2A "),ba=p(Cl,"CODE",{});var sr=i(ba);Br=a(sr,"Repository"),sr.forEach(s),Ul=a(Cl," \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 "),ft=p(Cl,"CODE",{});var to=i(ft);Nr=a(to,"repo_name"),to.forEach(s),Lr=a(Cl," \uFF1B\u5B83\u53EA\u9700\u8981\u5305\u542B\u60A8\u7684\u7528\u6237\u540D\uFF0C\u53EF\u4EE5\u4F7F\u7528"),mt=p(Cl,"CODE",{});var hn=i(mt);Fr=a(hn,"get_full_repo_name()"),hn.forEach(s),Mr=a(Cl,"\u51FD\u6570\u7684\u67E5\u770B\u76EE\u524D\u7684repo_name\uFF09\uFF1A"),Cl.forEach(s),$a=m(r),E(sl.$$.fragment,r),rr=m(r),E(Wl.$$.fragment,r),Xl=m(r),ut=p(r,"P",{});var ra=i(ut);_t=a(ra,"Then we can clone that repository in a local folder. If it already exists, this local folder should be an existing clone of the repository we are working with:"),ra.forEach(s),ka=m(r),E(Ye.$$.fragment,r),nr=m(r),hs=p(r,"P",{});var qt=i(hs);Hr=a(qt,"We can now upload anything we save in "),ja=p(qt,"CODE",{});var Tt=i(ja);ga=a(Tt,"output_dir"),Tt.forEach(s),Gr=a(qt," by calling the "),va=p(qt,"CODE",{});var ao=i(va);or=a(ao,"repo.push_to_hub()"),ao.forEach(s),dt=a(qt," method. This will help us upload the intermediate models at the end of each epoch."),qt.forEach(s),wa=m(r),bs=p(r,"H3",{class:!0});var Dt=i(bs);Zl=p(Dt,"A",{id:!0,class:!0,href:!0});var ro=i(Zl);Xt=p(ro,"SPAN",{});var no=i(Xt);E($s.$$.fragment,no),no.forEach(s),ro.forEach(s),pr=m(Dt),El=p(Dt,"SPAN",{});var bn=i(El);Ur=a(bn,"Training loop"),bn.forEach(s),Dt.forEach(s),Ea=m(r),Ps=p(r,"H3",{id:!0});var ll=i(Ps);ir=a(ll,"\u8BAD\u7EC3\u5FAA\u73AF"),ll.forEach(s),xl=a(r,"\n\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u7F16\u5199\u5B8C\u6574\u7684\u8BAD\u7EC3\u5FAA\u73AF\u3002\u4E3A\u4E86\u7B80\u5316\u5B83\u7684\u8BC4\u4F30\u90E8\u5206\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E86\u8FD9\u4E2A `postprocess()` \u63A5\u53D7\u9884\u6D4B\u548C\u6807\u7B7E\u5E76\u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32\u5217\u8868\u7684\u51FD\u6570\uFF0C\u4E5F\u5C31\u662F `metric`\u5BF9\u8C61\u9700\u8981\u7684\u8F93\u5165\u683C\u5F0F\uFF1A\n\n	"),E(ht.$$.fragment,r),bt=m(r),Zt=p(r,"P",{});var tl=i(Zt);Wr=a(tl,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7F16\u5199\u8BAD\u7EC3\u5FAA\u73AF\u3002\u5728\u5B9A\u4E49\u4E00\u4E2A\u8FDB\u5EA6\u6761\u6765\u8DDF\u8E2A\u8BAD\u7EC3\u7684\u8FDB\u884C\u540E\uFF0C\u5FAA\u73AF\u5206\u4E3A\u4E09\u4E2A\u90E8\u5206\uFF1A"),tl.forEach(s),xa=m(r),ze=p(r,"UL",{});var ql=i(ze);$t=p(ql,"LI",{});var et=i($t);ya=a(et,"\u8BAD\u7EC3\u672C\u8EAB\uFF0C\u8FD9\u662F\u5BF9"),Oa=p(et,"CODE",{});var oo=i(Oa);Xr=a(oo,"train_dataloader"),oo.forEach(s),cr=a(et,"\u7684\u7ECF\u5178\u8FED\u4EE3\uFF0C\u5411\u524D\u4F20\u9012\u6A21\u578B\uFF0C\u7136\u540E\u53CD\u5411\u4F20\u9012\u548C\u4F18\u5316\u53C2\u6570"),et.forEach(s),kt=m(ql),Je=p(ql,"LI",{});var Ss=i(Je);Ce=a(Ss,"\u8BC4\u4F30,\u5728\u83B7\u5F97\u6211\u4EEC\u6A21\u578B\u7684\u8F93\u51FA\u540E:\u56E0\u4E3A\u4E24\u4E2A\u8FDB\u7A0B\u53EF\u80FD\u5C06\u8F93\u5165\u548C\u6807\u7B7E\u586B\u5145\u6210\u4E0D\u540C\u7684\u5F62\u72B6,\u5728\u8C03\u7528"),Ca=p(Ss,"CODE",{});var Bs=i(Ca);qa=a(Bs,"gather()"),Bs.forEach(s),Zr=a(Ss,"\u65B9\u6CD5\u524D\u6211\u4EEC\u9700\u8981\u4F7F\u7528"),Ta=p(Ss,"CODE",{});var po=i(Ta);jt=a(po,"accelerator.pad_across_processes()"),po.forEach(s),Kr=a(Ss,"\u6765\u8BA9\u9884\u6D4B\u548C\u6807\u7B7E\u5F62\u72B6\u76F8\u540C\u3002\u5982\u679C\u6211\u4EEC\u4E0D\u8FD9\u6837\u505A\uFF0C\u8BC4\u4F30\u8981\u4E48\u51FA\u9519\uFF0C\u8981\u4E48\u6C38\u8FDC\u4E0D\u4F1A\u5F97\u5230\u7ED3\u679C\u3002\u7136\u540E\uFF0C\u6211\u4EEC\u5C06\u7ED3\u679C\u53D1\u9001\u7ED9"),Da=p(Ss,"CODE",{});var lr=i(Da);gt=a(lr,"metric.add_batch()"),lr.forEach(s),Vr=a(Ss,"\uFF0C\u5E76\u5728\u8BA1\u7B97\u5FAA\u73AF\u7ED3\u675F\u540E\u8C03\u7528"),Pa=p(Ss,"CODE",{});var io=i(Pa);za=a(io,"metric.compute()"),io.forEach(s),Yr=a(Ss,"\u3002"),Ss.forEach(s),Jr=m(ql),zs=p(ql,"LI",{});var na=i(zs);Qr=a(na,"\u4FDD\u5B58\u548C\u4E0A\u4F20\uFF0C\u9996\u5148\u4FDD\u5B58\u6A21\u578B\u548C\u6807\u8BB0\u5668\uFF0C\u7136\u540E\u8C03\u7528"),Aa=p(na,"CODE",{});var wr=i(Aa);fr=a(wr,"repo.push_to_hub()"),wr.forEach(s),vt=a(na,"\u3002\u6CE8\u610F\uFF0C\u6211\u4EEC\u4F7F\u7528\u53C2\u6570"),Kt=p(na,"CODE",{});var co=i(Kt);wt=a(co,"blocking=False"),co.forEach(s),mr=a(na,"\u544A\u8BC9\u{1F917} hub \u5E93\u7528\u5728\u5F02\u6B65\u8FDB\u7A0B\u4E2D\u63A8\u9001\u3002\u8FD9\u6837\uFF0C\u8BAD\u7EC3\u5C06\u6B63\u5E38\u7EE7\u7EED\uFF0C\u5E76\u4E14\u8BE5\uFF08\u957F\uFF09\u6307\u4EE4\u5C06\u5728\u540E\u53F0\u6267\u884C\u3002"),na.forEach(s),ql.forEach(s),As=m(r),Vt=p(r,"P",{});var fo=i(Vt);Ia=a(fo,"\u8FD9\u662F\u8BAD\u7EC3\u5FAA\u73AF\u7684\u5B8C\u6574\u4EE3\u7801\uFF1A"),fo.forEach(s),ur=m(r),E(Et.$$.fragment,r),Yt=m(r),Jt=p(r,"P",{});var Er=i(Jt);en=a(Er,"\u679C\u8FD9\u662F\u60A8\u7B2C\u4E00\u6B21\u770B\u5230\u7528 \u{1F917} Accelerate \u4FDD\u5B58\u7684\u6A21\u578B\uFF0C\u8BA9\u6211\u4EEC\u82B1\u70B9\u65F6\u95F4\u68C0\u67E5\u4E00\u4E0B\u5B83\u9644\u5E26\u7684\u4E09\u884C\u4EE3\u7801\uFF1A"),Er.forEach(s),Ra=m(r),E(Is.$$.fragment,r),Sa=m(r),oe=p(r,"P",{});var qe=i(oe);_r=a(qe,"\u7B2C\u4E00\u884C\u662F\u4E0D\u8A00\u81EA\u660E\u7684\uFF1A\u5B83\u544A\u8BC9\u6240\u6709\u8FDB\u7A0B\u7B49\u5230\u90FD\u5904\u4E8E\u90A3\u4E2A\u9636\u6BB5\u518D\u7EE7\u7EED(\u963B\u585E)\u3002\u8FD9\u662F\u4E3A\u4E86\u786E\u4FDD\u5728\u4FDD\u5B58\u4E4B\u524D\uFF0C\u6211\u4EEC\u5728\u6BCF\u4E2A\u8FC7\u7A0B\u4E2D\u90FD\u6709\u76F8\u540C\u7684\u6A21\u578B\u3002\u7136\u540E\u83B7\u53D6"),me=p(qe,"CODE",{});var mo=i(me);sn=a(mo,"unwrapped_model"),mo.forEach(s),Ba=a(qe,`\uFF0C\u5B83\u662F\u6211\u4EEC\u5B9A\u4E49\u7684\u57FA\u672C\u6A21\u578B\u3002
`),Na=p(qe,"CODE",{});var $n=i(Na);ln=a($n,"accelerator.prepare()"),$n.forEach(s),La=a(qe,"\u65B9\u6CD5\u5C06\u6A21\u578B\u66F4\u6539\u4E3A\u5728\u5206\u5E03\u5F0F\u8BAD\u7EC3\u4E2D\u5DE5\u4F5C\uFF0C\u6240\u4EE5\u5B83\u4E0D\u518D\u6709"),Fa=p(qe,"CODE",{});var Tl=i(Fa);tn=a(Tl,"save_pretraining()"),Tl.forEach(s),Ma=a(qe,"\u65B9\u6CD5;"),Ha=p(qe,"CODE",{});var uo=i(Ha);an=a(uo,"accelerator.unwrap_model()"),uo.forEach(s),Ga=a(qe,"\u65B9\u6CD5\u5C06\u64A4\u9500\u8BE5\u6B65\u9AA4\u3002\u6700\u540E\uFF0C\u6211\u4EEC\u8C03\u7528"),Ua=p(qe,"CODE",{});var oa=i(Ua);rn=a(oa,"save_pretraining()"),oa.forEach(s),Wa=a(qe,"\uFF0C\u4F46\u544A\u8BC9\u8BE5\u65B9\u6CD5\u4F7F\u7528"),Xa=p(qe,"CODE",{});var xr=i(Xa);nn=a(xr,"accelerator.save()"),xr.forEach(s),Qt=a(qe,"\u800C\u4E0D\u662F"),Za=p(qe,"CODE",{});var _o=i(Za);on=a(_o,"torch.save()"),_o.forEach(s),dr=a(qe,"\u3002"),qe.forEach(s),Kl=m(r),Rs=p(r,"P",{});var pa=i(Rs);xt=a(pa,"\u5F53\u5B8C\u6210\u4E4B\u540E\uFF0C\u4F60\u5E94\u8BE5\u6709\u4E00\u4E2A\u6A21\u578B\uFF0C\u5B83\u4EA7\u751F\u7684\u7ED3\u679C\u4E0E"),ea=p(pa,"CODE",{});var yr=i(ea);Qe=a(yr,"Trainer"),yr.forEach(s),pn=a(pa,"\u7684\u7ED3\u679C\u975E\u5E38\u76F8\u4F3C\u3002\u4F60\u53EF\u4EE5\u5728"),yl=p(pa,"A",{href:!0,rel:!0});var ho=i(yl);cn=a(ho,"hugs face-course/bert-fine - tuning -ner-accelerate"),ho.forEach(s),fn=a(pa,"\u4E2D\u67E5\u770B\u6211\u4EEC\u4F7F\u7528\u8FD9\u4E2A\u4EE3\u7801\u8BAD\u7EC3\u7684\u6A21\u578B\u3002\u5982\u679C\u4F60\u60F3\u6D4B\u8BD5\u8BAD\u7EC3\u5FAA\u73AF\u7684\u4EFB\u4F55\u8C03\u6574\uFF0C\u4F60\u53EF\u4EE5\u76F4\u63A5\u901A\u8FC7\u7F16\u8F91\u4E0A\u9762\u663E\u793A\u7684\u4EE3\u7801\u6765\u5B9E\u73B0\u5B83\u4EEC!"),pa.forEach(s),this.h()},h(){O(u,"id",""),O(fe,"href","/course/chapter3"),O(_e,"id",""),O(ls,"href","https://huggingface.co/huggingface-course"),O(ls,"rel","nofollow"),O(Xs,"id",""),O(Ts,"href","/course/chapter3/4"),O(Vs,"id",""),O(Zl,"id","training-loop"),O(Zl,"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"),O(Zl,"href","#training-loop"),O(bs,"class","relative group"),O(Ps,"id",""),O(yl,"href","https://huggingface.co/huggingface-course/bert-finetuned-ner-accelerate"),O(yl,"rel","nofollow")},m(r,h){n(r,u,h),l(u,j),n(r,d,h),n(r,$,h),l($,q),l($,v),l(v,b),l($,T),l($,S),l(S,R),l($,H),n(r,A,h),n(r,I,h),l(I,M),l(I,C),l(C,N),l(I,K),l(I,X),l(X,z),l(I,W),n(r,G,h),x(Q,r,h),n(r,Y,h),n(r,V,h),l(V,te),l(V,B),l(B,ee),l(V,U),n(r,Z,h),x(L,r,h),n(r,se,h),n(r,J,h),l(J,pe),l(J,fe),l(fe,ie),l(J,Se),l(J,re),l(re,Ns),l(J,js),n(r,ue,h),x(Be,r,h),n(r,Ls,h),x(ae,r,h),n(r,Dl,h),x(ke,r,h),n(r,je,h),n(r,_e,h),l(_e,Lt),n(r,rl,h),n(r,de,h),l(de,Ft),l(de,gs),l(gs,ge),l(de,Pl),n(r,Te,h),x(vs,r,h),n(r,nl,h),n(r,Ne,h),l(Ne,ws),n(r,ol,h),x(ve,r,h),n(r,Le,h),n(r,ce,h),l(ce,Es),l(ce,xs),l(xs,lt),l(ce,zl),n(r,De,h),x(cs,r,h),n(r,Fe,h),n(r,le,h),l(le,pl),l(le,es),l(es,Al),l(le,ss),l(le,ls),l(ls,he),l(he,fs),l(ls,il),l(le,cl),l(le,fl),l(fl,ml),l(le,Il),l(le,ts),l(ts,ul),l(le,be),l(le,_l),l(_l,ms),l(le,tt),n(r,Rl,h),x(as,r,h),n(r,we,h),n(r,Me,h),l(Me,ne),l(Me,Fs),l(Fs,He),l(Me,at),n(r,Ms,h),x(Ee,r,h),n(r,Hs,h),n(r,ys,h),l(ys,Gs),n(r,Sl,h),n(r,Pe,h),l(Pe,Os),l(Pe,Us),l(Us,rs),l(Pe,Bl),n(r,Cs,h),x(ns,r,h),n(r,dl,h),n(r,Ge,h),l(Ge,hl),n(r,xe,h),x(os,r,h),n(r,Ue,h),n(r,us,h),l(us,bl),l(us,ye),l(ye,Nl),l(us,_s),n(r,_,h),n(r,D,h),l(D,Ws),n(r,$l,h),n(r,Xs,h),l(Xs,Zs),n(r,kl,h),n(r,qs,h),l(qs,Ll),l(qs,Ts),l(Ts,Ks),l(qs,Mt),n(r,jl,h),n(r,Vs,h),l(Vs,Ht),n(r,Fl,h),x(We,r,h),n(r,Xe,h),n(r,ps,h),l(ps,rt),n(r,Ze,h),x(Ke,r,h),n(r,Ys,h),n(r,is,h),l(is,Ml),l(is,Js),l(Js,Oe),l(is,Gt),l(is,Qs),l(Qs,$e),l(is,gl),n(r,vl,h),x(el,r,h),n(r,nt,h),n(r,Ds,h),l(Ds,Hl),l(Ds,ot),l(ot,Pr),l(Ds,zr),n(r,Ut,h),x(pt,r,h),n(r,tr,h),x(it,r,h),n(r,wl,h),n(r,ds,h),l(ds,Ar),l(ds,_a),l(_a,da),l(ds,Ir),l(ds,ha),l(ha,Rr),l(ds,Gl),n(r,Wt,h),x(ct,r,h),n(r,ar,h),n(r,Ve,h),l(Ve,Sr),l(Ve,ba),l(ba,Br),l(Ve,Ul),l(Ve,ft),l(ft,Nr),l(Ve,Lr),l(Ve,mt),l(mt,Fr),l(Ve,Mr),n(r,$a,h),x(sl,r,h),n(r,rr,h),x(Wl,r,h),n(r,Xl,h),n(r,ut,h),l(ut,_t),n(r,ka,h),x(Ye,r,h),n(r,nr,h),n(r,hs,h),l(hs,Hr),l(hs,ja),l(ja,ga),l(hs,Gr),l(hs,va),l(va,or),l(hs,dt),n(r,wa,h),n(r,bs,h),l(bs,Zl),l(Zl,Xt),x($s,Xt,null),l(bs,pr),l(bs,El),l(El,Ur),n(r,Ea,h),n(r,Ps,h),l(Ps,ir),n(r,xl,h),x(ht,r,h),n(r,bt,h),n(r,Zt,h),l(Zt,Wr),n(r,xa,h),n(r,ze,h),l(ze,$t),l($t,ya),l($t,Oa),l(Oa,Xr),l($t,cr),l(ze,kt),l(ze,Je),l(Je,Ce),l(Je,Ca),l(Ca,qa),l(Je,Zr),l(Je,Ta),l(Ta,jt),l(Je,Kr),l(Je,Da),l(Da,gt),l(Je,Vr),l(Je,Pa),l(Pa,za),l(Je,Yr),l(ze,Jr),l(ze,zs),l(zs,Qr),l(zs,Aa),l(Aa,fr),l(zs,vt),l(zs,Kt),l(Kt,wt),l(zs,mr),n(r,As,h),n(r,Vt,h),l(Vt,Ia),n(r,ur,h),x(Et,r,h),n(r,Yt,h),n(r,Jt,h),l(Jt,en),n(r,Ra,h),x(Is,r,h),n(r,Sa,h),n(r,oe,h),l(oe,_r),l(oe,me),l(me,sn),l(oe,Ba),l(oe,Na),l(Na,ln),l(oe,La),l(oe,Fa),l(Fa,tn),l(oe,Ma),l(oe,Ha),l(Ha,an),l(oe,Ga),l(oe,Ua),l(Ua,rn),l(oe,Wa),l(oe,Xa),l(Xa,nn),l(oe,Qt),l(oe,Za),l(Za,on),l(oe,dr),n(r,Kl,h),n(r,Rs,h),l(Rs,xt),l(Rs,ea),l(ea,Qe),l(Rs,pn),l(Rs,yl),l(yl,cn),l(Rs,fn),sa=!0},i(r){sa||(k(Q.$$.fragment,r),k(L.$$.fragment,r),k(Be.$$.fragment,r),k(ae.$$.fragment,r),k(ke.$$.fragment,r),k(vs.$$.fragment,r),k(ve.$$.fragment,r),k(cs.$$.fragment,r),k(as.$$.fragment,r),k(Ee.$$.fragment,r),k(ns.$$.fragment,r),k(os.$$.fragment,r),k(We.$$.fragment,r),k(Ke.$$.fragment,r),k(el.$$.fragment,r),k(pt.$$.fragment,r),k(it.$$.fragment,r),k(ct.$$.fragment,r),k(sl.$$.fragment,r),k(Wl.$$.fragment,r),k(Ye.$$.fragment,r),k($s.$$.fragment,r),k(ht.$$.fragment,r),k(Et.$$.fragment,r),k(Is.$$.fragment,r),sa=!0)},o(r){g(Q.$$.fragment,r),g(L.$$.fragment,r),g(Be.$$.fragment,r),g(ae.$$.fragment,r),g(ke.$$.fragment,r),g(vs.$$.fragment,r),g(ve.$$.fragment,r),g(cs.$$.fragment,r),g(as.$$.fragment,r),g(Ee.$$.fragment,r),g(ns.$$.fragment,r),g(os.$$.fragment,r),g(We.$$.fragment,r),g(Ke.$$.fragment,r),g(el.$$.fragment,r),g(pt.$$.fragment,r),g(it.$$.fragment,r),g(ct.$$.fragment,r),g(sl.$$.fragment,r),g(Wl.$$.fragment,r),g(Ye.$$.fragment,r),g($s.$$.fragment,r),g(ht.$$.fragment,r),g(Et.$$.fragment,r),g(Is.$$.fragment,r),sa=!1},d(r){r&&s(u),r&&s(d),r&&s($),r&&s(A),r&&s(I),r&&s(G),y(Q,r),r&&s(Y),r&&s(V),r&&s(Z),y(L,r),r&&s(se),r&&s(J),r&&s(ue),y(Be,r),r&&s(Ls),y(ae,r),r&&s(Dl),y(ke,r),r&&s(je),r&&s(_e),r&&s(rl),r&&s(de),r&&s(Te),y(vs,r),r&&s(nl),r&&s(Ne),r&&s(ol),y(ve,r),r&&s(Le),r&&s(ce),r&&s(De),y(cs,r),r&&s(Fe),r&&s(le),r&&s(Rl),y(as,r),r&&s(we),r&&s(Me),r&&s(Ms),y(Ee,r),r&&s(Hs),r&&s(ys),r&&s(Sl),r&&s(Pe),r&&s(Cs),y(ns,r),r&&s(dl),r&&s(Ge),r&&s(xe),y(os,r),r&&s(Ue),r&&s(us),r&&s(_),r&&s(D),r&&s($l),r&&s(Xs),r&&s(kl),r&&s(qs),r&&s(jl),r&&s(Vs),r&&s(Fl),y(We,r),r&&s(Xe),r&&s(ps),r&&s(Ze),y(Ke,r),r&&s(Ys),r&&s(is),r&&s(vl),y(el,r),r&&s(nt),r&&s(Ds),r&&s(Ut),y(pt,r),r&&s(tr),y(it,r),r&&s(wl),r&&s(ds),r&&s(Wt),y(ct,r),r&&s(ar),r&&s(Ve),r&&s($a),y(sl,r),r&&s(rr),y(Wl,r),r&&s(Xl),r&&s(ut),r&&s(ka),y(Ye,r),r&&s(nr),r&&s(hs),r&&s(wa),r&&s(bs),y($s),r&&s(Ea),r&&s(Ps),r&&s(xl),y(ht,r),r&&s(bt),r&&s(Zt),r&&s(xa),r&&s(ze),r&&s(As),r&&s(Vt),r&&s(ur),y(Et,r),r&&s(Yt),r&&s(Jt),r&&s(Ra),y(Is,r),r&&s(Sa),r&&s(oe),r&&s(Kl),r&&s(Rs)}}}function Vc(F){let u,j;return{c(){u=o("p"),j=t("\u26A0\uFE0F \u5982\u679C\u6A21\u578B\u7684\u6807\u7B7E\u6570\u91CF\u9519\u8BEF\uFF0C\u7A0D\u540E\u8C03\u7528Trainer.train()\u65B9\u6CD5\u65F6\u4F1A\u51FA\u73B0\u4E00\u4E2A\u6A21\u7CCA\u7684\u9519\u8BEF\uFF08\u7C7B\u4F3C\u4E8E\u201CCUDA error: device-side assert triggered\u201D\uFF09\u3002\u8FD9\u662F\u7528\u6237\u62A5\u544A\u6B64\u7C7B\u9519\u8BEF\u7684\u7B2C\u4E00\u4E2A\u539F\u56E0\uFF0C\u56E0\u6B64\u8BF7\u786E\u4FDD\u8FDB\u884C\u8FD9\u6837\u7684\u68C0\u67E5\u4EE5\u786E\u8BA4\u60A8\u62E5\u6709\u9884\u671F\u6570\u91CF\u7684\u6807\u7B7E\u3002")},l(d){u=p(d,"P",{});var $=i(u);j=a($,"\u26A0\uFE0F \u5982\u679C\u6A21\u578B\u7684\u6807\u7B7E\u6570\u91CF\u9519\u8BEF\uFF0C\u7A0D\u540E\u8C03\u7528Trainer.train()\u65B9\u6CD5\u65F6\u4F1A\u51FA\u73B0\u4E00\u4E2A\u6A21\u7CCA\u7684\u9519\u8BEF\uFF08\u7C7B\u4F3C\u4E8E\u201CCUDA error: device-side assert triggered\u201D\uFF09\u3002\u8FD9\u662F\u7528\u6237\u62A5\u544A\u6B64\u7C7B\u9519\u8BEF\u7684\u7B2C\u4E00\u4E2A\u539F\u56E0\uFF0C\u56E0\u6B64\u8BF7\u786E\u4FDD\u8FDB\u884C\u8FD9\u6837\u7684\u68C0\u67E5\u4EE5\u786E\u8BA4\u60A8\u62E5\u6709\u9884\u671F\u6570\u91CF\u7684\u6807\u7B7E\u3002"),$.forEach(s)},m(d,$){n(d,u,$),l(u,j)},d(d){d&&s(u)}}}function Yc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u{1F4A1} \u5982\u679C\u60A8\u6B63\u5728\u4F7F\u7528\u7684\u8F93\u51FA\u76EE\u5F55\u5DF2\u7ECF\u5B58\u5728\uFF0C\u90A3\u4E48\u8F93\u51FA\u76EE\u5F55\u5FC5\u987B\u662F\u4ECE\u540C\u4E00\u4E2A\u5B58\u50A8\u5E93clone\u4E0B\u6765\u7684\u3002\u5982\u679C\u4E0D\u662F\uFF0C\u60A8\u5C06\u5728\u58F0\u660E "),d=o("code"),$=t("Trainer"),q=t(" \u65F6\u9047\u5230\u9519\u8BEF\uFF0C\u5E76\u4E14\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u65B0\u540D\u79F0\u3002")},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u{1F4A1} \u5982\u679C\u60A8\u6B63\u5728\u4F7F\u7528\u7684\u8F93\u51FA\u76EE\u5F55\u5DF2\u7ECF\u5B58\u5728\uFF0C\u90A3\u4E48\u8F93\u51FA\u76EE\u5F55\u5FC5\u987B\u662F\u4ECE\u540C\u4E00\u4E2A\u5B58\u50A8\u5E93clone\u4E0B\u6765\u7684\u3002\u5982\u679C\u4E0D\u662F\uFF0C\u60A8\u5C06\u5728\u58F0\u660E "),d=p(b,"CODE",{});var T=i(d);$=a(T,"Trainer"),T.forEach(s),q=a(b," \u65F6\u9047\u5230\u9519\u8BEF\uFF0C\u5E76\u4E14\u9700\u8981\u8BBE\u7F6E\u4E00\u4E2A\u65B0\u540D\u79F0\u3002"),b.forEach(s)},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Jc(F){let u,j,d,$,q;return{c(){u=o("p"),j=t("\u{1F6A8} \u5982\u679C\u60A8\u5728 TPU \u4E0A\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u5219\u9700\u8981\u5C06\u4EE5\u4E0A\u5355\u5143\u683C\u4E2D\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 "),d=o("a"),$=t("\u7B2C3\u7AE0"),q=t("\u3002"),this.h()},l(v){u=p(v,"P",{});var b=i(u);j=a(b,"\u{1F6A8} \u5982\u679C\u60A8\u5728 TPU \u4E0A\u8FDB\u884C\u8BAD\u7EC3\uFF0C\u5219\u9700\u8981\u5C06\u4EE5\u4E0A\u5355\u5143\u683C\u4E2D\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 "),d=p(b,"A",{href:!0});var T=i(d);$=a(T,"\u7B2C3\u7AE0"),T.forEach(s),q=a(b,"\u3002"),b.forEach(s),this.h()},h(){O(d,"href","/course/chapter3")},m(v,b){n(v,u,b),l(u,j),l(u,d),l(d,$),l(u,q)},d(v){v&&s(u)}}}function Qc(F){let u,j,d,$,q,v,b,T,S,R,H,A,I,M,C,N,K,X,z,W,G,Q,Y,V,te,B,ee,U,Z,L,se,J,pe,fe,ie,Se,re,Ns,js,ue,Be,Ls,ae,Dl,ke,je,_e,Lt,rl,de,Ft,gs,ge,Pl,Te,vs,nl,Ne,ws,ol,ve,Le,ce,Es,xs,lt,zl,De,cs,Fe,le,pl,es,Al,ss,ls,he,fs,il,cl,fl,ml,Il,ts,ul,be,_l,ms,tt,Rl,as,we,Me,ne,Fs,He,at,Ms,Ee,Hs,ys,Gs,Sl,Pe,Os,Us,rs,Bl,Cs,ns,dl,Ge,hl,xe,os,Ue,us,bl,ye,Nl,_s,_,D,Ws,$l,Xs,Zs,kl,qs,Ll,Ts,Ks,Mt,jl,Vs,Ht,Fl,We,Xe,ps,rt,Ze,Ke,Ys,is,Ml,Js,Oe,Gt,Qs,$e,gl,vl,el,nt,Ds,Hl,ot,Pr,zr,Ut,pt,tr,it,wl,ds,Ar,_a,da,Ir,ha,Rr,Gl,Wt,ct,ar,Ve,Sr,ba,Br,Ul,ft,Nr,Lr,mt,Fr,Mr,$a,sl,rr,Wl,Xl,ut,_t,ka,Ye,nr,hs,Hr,ja,ga,Gr,va,or,dt,wa,bs,Zl,Xt,$s,pr,El,Ur,Ea,Ps,ir,xl,ht,bt,Zt,Wr,xa,ze,$t,ya,Oa,Xr,cr,kt,Je,Ce,Ca,qa,Zr,Ta,jt,Kr,Da,gt,Vr,Pa,za,Yr,Jr,zs,Qr,Aa,fr,vt,Kt,wt,mr,As,Vt,Ia,ur,Et,Yt,Jt,en,Ra,Is,Sa,oe,_r,me,sn,Ba,Na,ln,La,Fa,tn,Ma,Ha,an,Ga,Ua,rn,Wa,Xa,nn,Qt,Za,on,dr,Kl,Rs,xt,ea,Qe,pn,yl,cn,fn,sa,r,h,Vl,Fn,Mn,Yl,Hn,Gn,Ka,la,yt,Va,Un,mn,Jl,un,ta,Ya,Ol,ks,hr,_n,Wn,br,Xn,Zn,Ja,Ot,dn,Ae,Kn,$r,kr,Vn,jr,Yn,gr,vr,Jn,Qn,Ql,eo,so,Qa,aa,Ct,er,lo,Cl,sr,to,hn,ra,qt,Tt,ao,Dt,ro,no,bn,ll,tl,ql,et,oo,Ss,Bs,po,lr,io,na,wr,co,fo,Er,qe,mo,$n,Tl,uo,oa,xr,_o,pa,yr,ho,xp,Wo,Pt,zt,bo,$o,yp,Xo,kn,Zo,jn,Ko,ko,Op,Vo,gn,Yo,vn,Jo,At,It,jo,go,wn,Cp,Qo,Rt,St,vo,En,ep,wo,qp,sp,xn,lp,yn,tp,Eo,Tp,ap,On,rp,xo,Dp,np,Cn,op,Bt,Nt,yo,Oo,qn,Pp,pp,Or,zp,So,Ap,Ip,ip,Tn,cp,Dn,fp,Co,Rp,mp;d=new Pc({props:{fw:F[0]}}),T=new Uo({});const Np=[Ac,zc],Pn=[];function Lp(e,c){return e[0]==="pt"?0:1}I=Lp(F),M=Pn[I]=Np[I](F),ie=new wc({props:{id:"wVHdVlPScxA"}}),De=new Dr({props:{$$slots:{default:[Ic]},$$scope:{ctx:F}}}),es=new Uo({}),ts=new P({props:{code:`from datasets import load_dataset

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

raw_datasets = load_dataset(<span class="hljs-string">&quot;conll2003&quot;</span>)`}}),we=new P({props:{code:"raw_datasets",highlighted:"raw_datasets"}}),ne=new P({props:{code:`DatasetDict({
    train: Dataset({
        features: ['chunk_tags', 'id', 'ner_tags', 'pos_tags', 'tokens'],
        num_rows: 14041
    })
    validation: Dataset({
        features: ['chunk_tags', 'id', 'ner_tags', 'pos_tags', 'tokens'],
        num_rows: 3250
    })
    test: Dataset({
        features: ['chunk_tags', 'id', 'ner_tags', 'pos_tags', 'tokens'],
        num_rows: 3453
    })
})`,highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">14041</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">3250</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">3453</span>
    })
})`}}),Os=new P({props:{code:'raw_datasets["train"][0]["tokens"]',highlighted:'raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>]'}}),rs=new P({props:{code:"['EU', 'rejects', 'German', 'call', 'to', 'boycott', 'British', 'lamb', '.']",highlighted:'[<span class="hljs-string">&#x27;EU&#x27;</span>, <span class="hljs-string">&#x27;rejects&#x27;</span>, <span class="hljs-string">&#x27;German&#x27;</span>, <span class="hljs-string">&#x27;call&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;boycott&#x27;</span>, <span class="hljs-string">&#x27;British&#x27;</span>, <span class="hljs-string">&#x27;lamb&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>]'}}),Ge=new P({props:{code:'raw_datasets["train"][0]["ner_tags"]',highlighted:'raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]'}}),xe=new P({props:{code:"[3, 0, 7, 0, 0, 0, 7, 0, 0]",highlighted:'[<span class="hljs-number">3</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]'}}),ye=new P({props:{code:`ner_feature = raw_datasets["train"].features["ner_tags"]
ner_feature`,highlighted:`ner_feature = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;ner_tags&quot;</span>]
ner_feature`}}),_s=new P({props:{code:"Sequence(feature=ClassLabel(num_classes=9, names=['O', 'B-PER', 'I-PER', 'B-ORG', 'I-ORG', 'B-LOC', 'I-LOC', 'B-MISC', 'I-MISC'], names_file=None, id=None), length=-1, id=None)",highlighted:'<span class="hljs-type">Sequence</span>(feature=ClassLabel(num_classes=<span class="hljs-number">9</span>, names=[<span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-PER&#x27;</span>, <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;B-LOC&#x27;</span>, <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;I-MISC&#x27;</span>], names_file=<span class="hljs-literal">None</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>)'}}),We=new P({props:{code:`label_names = ner_feature.feature.names
label_names`,highlighted:`label_names = ner_feature.feature.names
label_names`}}),ps=new P({props:{code:"['O', 'B-PER', 'I-PER', 'B-ORG', 'I-ORG', 'B-LOC', 'I-LOC', 'B-MISC', 'I-MISC']",highlighted:'[<span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-PER&#x27;</span>, <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;B-LOC&#x27;</span>, <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;I-MISC&#x27;</span>]'}}),Xl=new P({props:{code:`words = raw_datasets["train"][0]["tokens"]
labels = raw_datasets["train"][0]["ner_tags"]
line1 = ""
line2 = ""
for word, label in zip(words, labels):
    full_label = label_names[label]
    max_length = max(len(word), len(full_label))
    line1 += word + " " * (max_length - len(word) + 1)
    line2 += full_label + " " * (max_length - len(full_label) + 1)

print(line1)
print(line2)`,highlighted:`words = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>]
labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
line1 = <span class="hljs-string">&quot;&quot;</span>
line2 = <span class="hljs-string">&quot;&quot;</span>
<span class="hljs-keyword">for</span> word, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(words, labels):
    full_label = label_names[label]
    max_length = <span class="hljs-built_in">max</span>(<span class="hljs-built_in">len</span>(word), <span class="hljs-built_in">len</span>(full_label))
    line1 += word + <span class="hljs-string">&quot; &quot;</span> * (max_length - <span class="hljs-built_in">len</span>(word) + <span class="hljs-number">1</span>)
    line2 += full_label + <span class="hljs-string">&quot; &quot;</span> * (max_length - <span class="hljs-built_in">len</span>(full_label) + <span class="hljs-number">1</span>)

<span class="hljs-built_in">print</span>(line1)
<span class="hljs-built_in">print</span>(line2)`}}),_t=new P({props:{code:`'EU    rejects German call to boycott British lamb .'
'B-ORG O       B-MISC O    O  O       B-MISC  O    O'`,highlighted:`<span class="hljs-string">&#x27;EU    rejects German call to boycott British lamb .&#x27;</span>
<span class="hljs-string">&#x27;B-ORG O       B-MISC O    O  O       B-MISC  O    O&#x27;</span>`}}),dt=new P({props:{code:`'Germany \\'s representative to the European Union \\'s veterinary committee Werner Zwingmann said on Wednesday consumers should buy sheepmeat from countries other than Britain until the scientific advice was clearer .'
'B-LOC   O  O              O  O   B-ORG    I-ORG O  O          O         B-PER  I-PER     O    O  O         O         O      O   O         O    O         O     O    B-LOC   O     O   O          O      O   O       O'`,highlighted:`<span class="hljs-string">&#x27;Germany \\&#x27;s representative to the European Union \\&#x27;s veterinary committee Werner Zwingmann said on Wednesday consumers should buy sheepmeat from countries other than Britain until the scientific advice was clearer .&#x27;</span>
<span class="hljs-string">&#x27;B-LOC   O  O              O  O   B-ORG    I-ORG O  O          O         B-PER  I-PER     O    O  O         O         O      O   O         O    O         O     O    B-LOC   O     O   O          O      O   O       O&#x27;</span>`}}),$s=new Dr({props:{$$slots:{default:[Rc]},$$scope:{ctx:F}}}),Ps=new wc({props:{id:"iY2AZYdZAr0"}}),kt=new P({props:{code:`from transformers import AutoTokenizer

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

model_checkpoint = <span class="hljs-string">&quot;bert-base-cased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`}}),vt=new P({props:{code:"tokenizer.is_fast",highlighted:"tokenizer.is_fast"}}),wt=new P({props:{code:"True",highlighted:'<span class="hljs-literal">True</span>'}}),Is=new P({props:{code:`inputs = tokenizer(raw_datasets["train"][0]["tokens"], is_split_into_words=True)
inputs.tokens()`,highlighted:`inputs = tokenizer(raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>], is_split_into_words=<span class="hljs-literal">True</span>)
inputs.tokens()`}}),oe=new P({props:{code:"['[CLS]', 'EU', 'rejects', 'German', 'call', 'to', 'boycott', 'British', 'la', '##mb', '.', '[SEP]']",highlighted:'[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;EU&#x27;</span>, <span class="hljs-string">&#x27;rejects&#x27;</span>, <span class="hljs-string">&#x27;German&#x27;</span>, <span class="hljs-string">&#x27;call&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;boycott&#x27;</span>, <span class="hljs-string">&#x27;British&#x27;</span>, <span class="hljs-string">&#x27;la&#x27;</span>, <span class="hljs-string">&#x27;##mb&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]'}}),Kl=new P({props:{code:"inputs.word_ids()",highlighted:"inputs.word_ids()"}}),xt=new P({props:{code:"[None, 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, None]",highlighted:'[<span class="hljs-literal">None</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-literal">None</span>]'}}),la=new P({props:{code:`def align_labels_with_tokens(labels, word_ids):
    new_labels = []
    current_word = None
    for word_id in word_ids:
        if word_id != current_word:
            # Start of a new word!
            current_word = word_id
            label = -100 if word_id is None else labels[word_id]
            new_labels.append(label)
        elif word_id is None:
            # Special token
            new_labels.append(-100)
        else:
            # Same word as previous token
            label = labels[word_id]
            # If the label is B-XXX we change it to I-XXX
            if label % 2 == 1:
                label += 1
            new_labels.append(label)

    return new_labels`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">align_labels_with_tokens</span>(<span class="hljs-params">labels, word_ids</span>):
    new_labels = []
    current_word = <span class="hljs-literal">None</span>
    <span class="hljs-keyword">for</span> word_id <span class="hljs-keyword">in</span> word_ids:
        <span class="hljs-keyword">if</span> word_id != current_word:
            <span class="hljs-comment"># Start of a new word!</span>
            current_word = word_id
            label = -<span class="hljs-number">100</span> <span class="hljs-keyword">if</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">else</span> labels[word_id]
            new_labels.append(label)
        <span class="hljs-keyword">elif</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
            <span class="hljs-comment"># Special token</span>
            new_labels.append(-<span class="hljs-number">100</span>)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># Same word as previous token</span>
            label = labels[word_id]
            <span class="hljs-comment"># If the label is B-XXX we change it to I-XXX</span>
            <span class="hljs-keyword">if</span> label % <span class="hljs-number">2</span> == <span class="hljs-number">1</span>:
                label += <span class="hljs-number">1</span>
            new_labels.append(label)

    <span class="hljs-keyword">return</span> new_labels`}}),Jl=new P({props:{code:`labels = raw_datasets["train"][0]["ner_tags"]
word_ids = inputs.word_ids()
print(labels)
print(align_labels_with_tokens(labels, word_ids))`,highlighted:`labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
word_ids = inputs.word_ids()
<span class="hljs-built_in">print</span>(labels)
<span class="hljs-built_in">print</span>(align_labels_with_tokens(labels, word_ids))`}}),ta=new P({props:{code:`[3, 0, 7, 0, 0, 0, 7, 0, 0]
[-100, 3, 0, 7, 0, 0, 0, 7, 0, 0, 0, -100]`,highlighted:`[<span class="hljs-number">3</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]
[-<span class="hljs-number">100</span>, <span class="hljs-number">3</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>]`}}),Ot=new Dr({props:{$$slots:{default:[Sc]},$$scope:{ctx:F}}}),aa=new P({props:{code:`def tokenize_and_align_labels(examples):
    tokenized_inputs = tokenizer(
        examples["tokens"], truncation=True, is_split_into_words=True
    )
    all_labels = examples["ner_tags"]
    new_labels = []
    for i, labels in enumerate(all_labels):
        word_ids = tokenized_inputs.word_ids(i)
        new_labels.append(align_labels_with_tokens(labels, word_ids))

    tokenized_inputs["labels"] = new_labels
    return tokenized_inputs`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_and_align_labels</span>(<span class="hljs-params">examples</span>):
    tokenized_inputs = tokenizer(
        examples[<span class="hljs-string">&quot;tokens&quot;</span>], truncation=<span class="hljs-literal">True</span>, is_split_into_words=<span class="hljs-literal">True</span>
    )
    all_labels = examples[<span class="hljs-string">&quot;ner_tags&quot;</span>]
    new_labels = []
    <span class="hljs-keyword">for</span> i, labels <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(all_labels):
        word_ids = tokenized_inputs.word_ids(i)
        new_labels.append(align_labels_with_tokens(labels, word_ids))

    tokenized_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = new_labels
    <span class="hljs-keyword">return</span> tokenized_inputs`}}),ra=new P({props:{code:`tokenized_datasets = raw_datasets.map(
    tokenize_and_align_labels,
    batched=True,
    remove_columns=raw_datasets["train"].column_names,
)`,highlighted:`tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(
    tokenize_and_align_labels,
    batched=<span class="hljs-literal">True</span>,
    remove_columns=raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names,
)`}});const Fp=[Nc,Bc],zn=[];function Mp(e,c){return e[0]==="pt"?0:1}ll=Mp(F),tl=zn[ll]=Fp[ll](F);const Hp=[Fc,Lc],An=[];function Gp(e,c){return e[0]==="pt"?0:1}Pt=Gp(F),zt=An[Pt]=Hp[Pt](F),kn=new P({props:{code:`batch = data_collator([tokenized_datasets["train"][i] for i in range(2)])
batch["labels"]`,highlighted:`batch = data_collator([tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>)])
batch[<span class="hljs-string">&quot;labels&quot;</span>]`}}),jn=new P({props:{code:`tensor([[-100,    3,    0,    7,    0,    0,    0,    7,    0,    0,    0, -100],
        [-100,    1,    2, -100, -100, -100, -100, -100, -100, -100, -100, -100]])`,highlighted:`tensor([[-<span class="hljs-number">100</span>,    <span class="hljs-number">3</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">7</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">7</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>],
        [-<span class="hljs-number">100</span>,    <span class="hljs-number">1</span>,    <span class="hljs-number">2</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>]])`}}),gn=new P({props:{code:`for i in range(2):
    print(tokenized_datasets["train"][i]["labels"])`,highlighted:`<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    <span class="hljs-built_in">print</span>(tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i][<span class="hljs-string">&quot;labels&quot;</span>])`}}),vn=new P({props:{code:`[-100, 3, 0, 7, 0, 0, 0, 7, 0, 0, 0, -100]
[-100, 1, 2, -100]`,highlighted:`[-<span class="hljs-number">100</span>, <span class="hljs-number">3</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>]
[-<span class="hljs-number">100</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, -<span class="hljs-number">100</span>]`}});const Up=[Hc,Mc],In=[];function Wp(e,c){return e[0]==="pt"?0:1}At=Wp(F),It=In[At]=Up[At](F);let Ie=F[0]==="tf"&&Ec(F);const Xp=[Xc,Wc],Rn=[];function Zp(e,c){return e[0]==="pt"?0:1}Rt=Zp(F),St=Rn[Rt]=Xp[Rt](F),En=new P({props:{code:`from datasets import load_metric

metric = load_metric("seqeval")`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

metric = load_metric(<span class="hljs-string">&quot;seqeval&quot;</span>)`}}),xn=new P({props:{code:`labels = raw_datasets["train"][0]["ner_tags"]
labels = [label_names[i] for i in labels]
labels`,highlighted:`labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
labels = [label_names[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> labels]
labels`}}),yn=new P({props:{code:"['B-ORG', 'O', 'B-MISC', 'O', 'O', 'O', 'B-MISC', 'O', 'O']",highlighted:'[<span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>]'}}),On=new P({props:{code:`predictions = labels.copy()
predictions[2] = "O"
metric.compute(predictions=[predictions], references=[labels])`,highlighted:`predictions = labels.copy()
predictions[<span class="hljs-number">2</span>] = <span class="hljs-string">&quot;O&quot;</span>
metric.compute(predictions=[predictions], references=[labels])`}}),Cn=new P({props:{code:`{'MISC': {'precision': 1.0, 'recall': 0.5, 'f1': 0.67, 'number': 2},
 'ORG': {'precision': 1.0, 'recall': 1.0, 'f1': 1.0, 'number': 1},
 'overall_precision': 1.0,
 'overall_recall': 0.67,
 'overall_f1': 0.8,
 'overall_accuracy': 0.89}`,highlighted:`{<span class="hljs-string">&#x27;MISC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.5</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.67</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">2</span>},
 <span class="hljs-string">&#x27;ORG&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1</span>},
 <span class="hljs-string">&#x27;overall_precision&#x27;</span>: <span class="hljs-number">1.0</span>,
 <span class="hljs-string">&#x27;overall_recall&#x27;</span>: <span class="hljs-number">0.67</span>,
 <span class="hljs-string">&#x27;overall_f1&#x27;</span>: <span class="hljs-number">0.8</span>,
 <span class="hljs-string">&#x27;overall_accuracy&#x27;</span>: <span class="hljs-number">0.89</span>}`}});const Kp=[Kc,Zc],Sn=[];function Vp(e,c){return e[0]==="pt"?0:1}Bt=Vp(F),Nt=Sn[Bt]=Kp[Bt](F);let Re=F[0]==="pt"&&xc(F);return Tn=new P({props:{code:`from transformers import pipeline

# Replace this with your own checkpoint
model_checkpoint = "huggingface-course/bert-finetuned-ner"
token_classifier = pipeline(
    "token-classification", model=model_checkpoint, aggregation_strategy="simple"
)
token_classifier("My name is Sylvain and I work at Hugging Face in Brooklyn.")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-comment"># Replace this with your own checkpoint</span>
model_checkpoint = <span class="hljs-string">&quot;huggingface-course/bert-finetuned-ner&quot;</span>
token_classifier = pipeline(
    <span class="hljs-string">&quot;token-classification&quot;</span>, model=model_checkpoint, aggregation_strategy=<span class="hljs-string">&quot;simple&quot;</span>
)
token_classifier(<span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>)`}}),Dn=new P({props:{code:`[{'entity_group': 'PER', 'score': 0.9988506, 'word': 'Sylvain', 'start': 11, 'end': 18},
 {'entity_group': 'ORG', 'score': 0.9647625, 'word': 'Hugging Face', 'start': 33, 'end': 45},
 {'entity_group': 'LOC', 'score': 0.9986118, 'word': 'Brooklyn', 'start': 49, 'end': 57}]`,highlighted:`[{<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9988506</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Sylvain&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">18</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9647625</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hugging Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9986118</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`}}),{c(){u=o("meta"),j=f(),w(d.$$.fragment),$=f(),q=o("h1"),v=o("a"),b=o("span"),w(T.$$.fragment),S=f(),R=o("span"),H=t("Token \u5206\u7C7B"),A=f(),M.c(),C=f(),N=o("p"),K=t("\u6211\u4EEC\u5C06\u63A2\u7D22\u7684\u7B2C\u4E00\u4E2A\u5E94\u7528\u662FToken\u5206\u7C7B\u3002\u8FD9\u4E2A\u901A\u7528\u4EFB\u52A1\u5305\u62EC\u4EFB\u4F55\u53EF\u4EE5\u8868\u8FF0\u4E3A\u201C\u4E3A\u53E5\u5B50\u4E2D\u7684\u8BCD\u6216\u5B57\u5206\u914D\u6807\u7B7E\u201D\u7684\u95EE\u9898\uFF0C\u4F8B\u5982\uFF1A"),X=f(),z=o("ul"),W=o("li"),G=o("strong"),Q=t("\u5B9E\u4F53\u547D\u540D\u8BC6\u522B (NER)"),Y=t(": \u627E\u51FA\u53E5\u5B50\u4E2D\u7684\u5B9E\u4F53\uFF08\u5982\u4EBA\u7269\u3001\u5730\u70B9\u6216\u7EC4\u7EC7\uFF09\u3002\u8FD9\u53EF\u4EE5\u901A\u8FC7\u4E3A\u6BCF\u4E2A\u5B9E\u4F53\u6216\u201C\u65E0\u5B9E\u4F53\u201D\u6307\u5B9A\u4E00\u4E2A\u7C7B\u522B\u7684\u6807\u7B7E\u3002"),V=f(),te=o("li"),B=o("strong"),ee=t("\u8BCD\u6027\u6807\u6CE8 (POS)"),U=t(": \u5C06\u53E5\u5B50\u4E2D\u7684\u6BCF\u4E2A\u5355\u8BCD\u6807\u8BB0\u4E3A\u5BF9\u5E94\u4E8E\u7279\u5B9A\u7684\u8BCD\u6027\uFF08\u5982\u540D\u8BCD\u3001\u52A8\u8BCD\u3001\u5F62\u5BB9\u8BCD\u7B49\uFF09\u3002"),Z=f(),L=o("li"),se=o("strong"),J=t("\u5206\u5757\uFF08chunking\uFF09"),pe=t(": \u627E\u5230\u5C5E\u4E8E\u540C\u4E00\u5B9E\u4F53\u7684Token\u3002\u8FD9\u4E2A\u4EFB\u52A1(\u53EF\u7ED3\u5408POS\u6216NER)\u53EF\u4EE5\u4EFB\u4F55\u5C06\u4E00\u5757Token\u4F5C\u4E3A\u5236\u5B9A\u4E00\u4E2A\u6807\u7B7E(\u901A\u5E38\u662FB -),\u53E6\u4E00\u4E2A\u6807\u7B7E(\u901A\u5E38I -)\u8868\u793AToken\u662F\u5426\u662F\u540C\u4E00\u5757,\u548C\u7B2C\u4E09\u4E2A\u6807\u7B7E(\u901A\u5E38\u662FO)\u8868\u793AToken\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u5757\u3002\u4E5F\u5C31\u662F\u6807\u51FA\u53E5\u5B50\u4E2D\u7684\u77ED\u8BED\u5757\uFF0C\u4F8B\u5982\u540D\u8BCD\u77ED\u8BED\uFF08NP\uFF09\uFF0C\u52A8\u8BCD\u77ED\u8BED\uFF08VP\uFF09\u7B49\u3002"),fe=f(),w(ie.$$.fragment),Se=f(),re=o("p"),Ns=t("\u5F53\u7136\uFF0C\u8FD8\u6709\u5F88\u591A\u5176\u4ED6\u7C7B\u578B\u7684token\u5206\u7C7B\u95EE\u9898\uFF1B\u8FD9\u4E9B\u53EA\u662F\u51E0\u4E2A\u6709\u4EE3\u8868\u6027\u7684\u4F8B\u5B50\u3002\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u5728 NER \u4EFB\u52A1\u4E0A\u5FAE\u8C03\u6A21\u578B (BERT)\uFF0C\u7136\u540E\u8BE5\u6A21\u578B\u5C06\u80FD\u591F\u8BA1\u7B97\u5982\u4E0B\u9884\u6D4B\uFF1A"),js=f(),ue=o("iframe"),Ls=f(),ae=o("iframe"),ke=f(),je=o("a"),_e=o("img"),rl=f(),de=o("img"),gs=f(),ge=o("p"),Pl=t("\u60A8\u53EF\u4EE5"),Te=o("a"),vs=t("\u5728\u8FD9\u91CC"),nl=t(".\u627E\u5230\u6211\u4EEC\u5C06\u8BAD\u7EC3\u5E76\u4E0A\u4F20\u5230 Hub\u7684\u6A21\u578B\uFF0C\u53EF\u4EE5\u5C1D\u8BD5\u8F93\u5165\u4E00\u4E9B\u53E5\u5B50\u770B\u770B\u6A21\u578B\u7684\u9884\u6D4B\u7ED3\u679C\u3002"),Ne=f(),ws=o("h2"),ol=t("\u51C6\u5907\u6570\u636E"),ve=f(),Le=o("p"),ce=t("\u9996\u5148\uFF0C\u6211\u4EEC\u9700\u8981\u4E00\u4E2A\u9002\u5408\u6807\u8BB0\u5206\u7C7B\u7684\u6570\u636E\u96C6\u3002\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528"),Es=o("a"),xs=t("CoNLL-2003 \u6570\u636E\u96C6"),lt=t(", \u5176\u4E2D\u5305\u542B\u6765\u81EA\u8DEF\u900F\u793E\u7684\u65B0\u95FB\u62A5\u9053\u3002"),zl=f(),w(De.$$.fragment),cs=f(),Fe=o("h3"),le=o("a"),pl=o("span"),w(es.$$.fragment),Al=f(),ss=o("span"),ls=t("CoNLL-2003 \u6570\u636E\u96C6"),he=f(),fs=o("p"),il=t("\u8981\u52A0\u8F7D CoNLL-2003 \u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u4F7F\u7528 \u6765\u81EA \u{1F917} Datasets \u5E93\u7684"),cl=o("strong"),fl=t("load_dataset()"),ml=t(" \u65B9\u6CD5\uFF1A"),Il=f(),w(ts.$$.fragment),ul=f(),be=o("p"),_l=t("\u8FD9\u5C06\u4E0B\u8F7D\u5E76\u7F13\u5B58\u6570\u636E\u96C6\uFF0C\u5C31\u50CF\u548C\u6211\u4EEC\u5728"),ms=o("a"),tt=t("\u7B2C\u4E09\u7AE0"),Rl=t(" \u52A0\u8F7DGLUE MRPC \u6570\u636E\u96C6\u4E00\u6837\u3002\u68C0\u67E5\u8FD9\u4E2A\u5BF9\u8C61\u53EF\u4EE5\u8BA9\u6211\u4EEC\u770B\u5230\u5B58\u5728\u54EA\u4E9B\u5217\uFF0C\u4EE5\u53CA\u8BAD\u7EC3\u96C6\u3001\u9A8C\u8BC1\u96C6\u548C\u6D4B\u8BD5\u96C6\u4E4B\u95F4\u662F\u5982\u4F55\u5206\u5272\u7684:"),as=f(),w(we.$$.fragment),Me=f(),w(ne.$$.fragment),Fs=f(),He=o("p"),at=t("\u7279\u522B\u662F\uFF0C\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u6570\u636E\u96C6\u5305\u542B\u6211\u4EEC\u4E4B\u524D\u63D0\u5230\u7684\u4E09\u4E2A\u4EFB\u52A1\u7684\u6807\u7B7E\uFF1ANER\u3001POS \u548Cchunking\u3002\u4E0E\u5176\u4ED6\u6570\u636E\u96C6\u7684\u4E00\u4E2A\u5F88\u5927\u533A\u522B\u662F\u8F93\u5165\u6587\u672C\u4E0D\u662F\u4F5C\u4E3A\u53E5\u5B50\u6216\u6587\u6863\u5448\u73B0\u7684\uFF0C\u800C\u662F\u5355\u8BCD\u5217\u8868\uFF08\u6700\u540E\u4E00\u5217\u79F0\u4E3A "),Ms=o("strong"),Ee=t("tokens"),Hs=t(" \uFF0C\u4F46\u5B83\u5305\u542B\u7684\u662F\u8FD9\u4E9B\u8BCD\u662F\u9884\u5148\u6807\u8BB0\u5316\u7684\u8F93\u5165\uFF0C\u4ECD\u7136\u9700\u8981\u901A\u8FC7\u6807\u8BB0\u5668\u8FDB\u884C\u5B50\u8BCD\u6807\u8BB0\uFF09\u3002"),ys=f(),Gs=o("p"),Sl=t("\u6211\u4EEC\u6765\u770B\u770B\u8BAD\u7EC3\u96C6\u7684\u7B2C\u4E00\u4E2A\u5143\u7D20\uFF1A"),Pe=f(),w(Os.$$.fragment),Us=f(),w(rs.$$.fragment),Bl=f(),Cs=o("p"),ns=t("\u7531\u4E8E\u6211\u4EEC\u8981\u6267\u884C\u547D\u540D\u5B9E\u4F53\u8BC6\u522B\uFF0C\u6211\u4EEC\u5C06\u67E5\u770B NER \u6807\u7B7E\uFF1A"),dl=f(),w(Ge.$$.fragment),hl=f(),w(xe.$$.fragment),os=f(),Ue=o("p"),us=t("\u8FD9\u4E00\u5217\u662F\u7C7B\u6807\u7B7E\u7684\u5E8F\u5217\u3002\u5143\u7D20\u7684\u7C7B\u578B\u5728ner_feature\u7684feature\u5C5E\u6027\u4E2D\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u8BE5\u7279\u6027\u7684names\u5C5E\u6027\u6765\u8BBF\u95EE\u540D\u79F0\u5217\u8868:"),bl=f(),w(ye.$$.fragment),Nl=f(),w(_s.$$.fragment),_=f(),D=o("p"),Ws=t("\u56E0\u6B64\uFF0C\u8FD9\u4E00\u5217\u5305\u542B\u7684\u5143\u7D20\u662FClassLabels\u7684\u5E8F\u5217\u3002\u5E8F\u5217\u5143\u7D20\u7684\u7C7B\u578B\u5728"),$l=o("code"),Xs=t("ner_feature"),Zs=t("\u7684"),kl=o("code"),qs=t("feature"),Ll=t("\u4E2D\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u8BE5"),Ts=o("code"),Ks=t("feature"),Mt=t("\u7684"),jl=o("code"),Vs=t("names"),Ht=t("\u5C5E\u6027\u6765\u8BBF\u95EE\u540D\u79F0\u5217\u8868:"),Fl=f(),w(We.$$.fragment),Xe=f(),w(ps.$$.fragment),rt=f(),Ze=o("p"),Ke=t("\u6211\u4EEC\u5728"),Ys=o("a"),is=t("\u7B2C\u516D\u7AE0"),Ml=t(", \u6DF1\u5165\u7814\u7A76"),Js=o("strong"),Oe=t("token-classification"),Gt=t(" \u7BA1\u9053\u65F6\u5DF2\u7ECF\u770B\u5230\u4E86\u8FD9\u4E9B\u6807\u7B7E \uFF0C\u4F46\u4E3A\u4E86\u5FEB\u901F\u590D\u4E60\uFF1A"),Qs=f(),$e=o("ul"),gl=o("li"),vl=o("code"),el=t("O"),nt=t(" \u8868\u793A\u8FD9\u4E2A\u8BCD\u4E0D\u5BF9\u5E94\u4EFB\u4F55\u5B9E\u4F53\u3002"),Ds=f(),Hl=o("li"),ot=o("code"),Pr=t("B-PER"),zr=t("/"),Ut=o("code"),pt=t("I-PER"),tr=t("\u610F\u5473\u7740\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u4EBA\u540D\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),it=f(),wl=o("li"),ds=o("code"),Ar=t("B-ORG"),_a=t("/"),da=o("code"),Ir=t("I-ORG"),ha=t(" \u7684\u610F\u601D\u662F\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u7EC4\u7EC7\u540D\u79F0\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Rr=f(),Gl=o("li"),Wt=o("code"),ct=t("B-LOC"),ar=t("/"),Ve=o("code"),Sr=t("I-LOC"),ba=t(" \u6307\u7684\u662F\u662F\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u5730\u540D\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Br=f(),Ul=o("li"),ft=o("code"),Nr=t("B-MISC"),Lr=t("/"),mt=o("code"),Fr=t("I-MISC"),Mr=t(" \u8868\u793A\u8BE5\u8BCD\u5BF9\u5E94\u4E8E\u4E00\u4E2A\u6742\u9879\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),$a=f(),sl=o("p"),rr=t("\u73B0\u5728\u89E3\u7801\u6211\u4EEC\u4E4B\u524D\u770B\u5230\u7684\u6807\u7B7E\uFF1A"),Wl=f(),w(Xl.$$.fragment),ut=f(),w(_t.$$.fragment),ka=f(),Ye=o("p"),nr=t("\u4F8B\u5982\u6DF7\u5408 "),hs=o("strong"),Hr=t("B-"),ja=t(" \u548C "),ga=o("strong"),Gr=t("I-"),va=t(" \u6807\u7B7E\uFF0C\u8FD9\u662F\u76F8\u540C\u7684\u4EE3\u7801\u5728\u7D22\u5F15 4 \u7684\u8BAD\u7EC3\u96C6\u5143\u7D20\u4E0A\u7684\u9884\u6D4B\u7ED3\u679C\uFF1A"),or=f(),w(dt.$$.fragment),wa=f(),bs=o("p"),Zl=t("\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u8DE8\u8D8A\u4E24\u4E2A\u5355\u8BCD\u7684\u5B9E\u4F53\uFF0C\u5982\u201CEuropean Union\u201D\u548C\u201CWerner Zwingmann\u201D\uFF0C\u6A21\u578B\u4E3A\u7B2C\u4E00\u4E2A\u5355\u8BCD\u6807\u6CE8\u4E86\u4E00\u4E2AB-\u6807\u7B7E\uFF0C\u4E3A\u7B2C\u4E8C\u4E2A\u5355\u8BCD\u6807\u6CE8\u4E86\u4E00\u4E2AI-\u6807\u7B7E\u3002"),Xt=f(),w($s.$$.fragment),pr=f(),El=o("h3"),Ur=t("\u5904\u7406\u6570\u636E"),Ea=f(),w(Ps.$$.fragment),ir=f(),xl=o("p"),ht=t("\u50CF\u5F80\u5E38\u4E00\u6837\uFF0C\u6211\u4EEC\u7684\u6587\u672C\u9700\u8981\u8F6C\u6362\u4E3AToken ID\uFF0C\u7136\u540E\u6A21\u578B\u624D\u80FD\u7406\u89E3\u5B83\u4EEC\u3002\u6B63\u5982\u6211\u4EEC\u5728"),bt=o("a"),Zt=t("\u7B2C\u516D\u7AE0"),Wr=t("\u6240\u5B66\u7684\u90A3\u6837\u3002\u4E0D\u8FC7\u5728\u6807\u8BB0\u4EFB\u52A1\u4E2D\uFF0C\u4E00\u4E2A\u5F88\u5927\u7684\u533A\u522B\u662F\u6211\u4EEC\u6709pre-tokenized\u7684\u8F93\u5165\u3002\u5E78\u8FD0\u7684\u662F\uFF0Ctokenizer API\u53EF\u4EE5\u5F88\u5BB9\u6613\u5730\u5904\u7406\u8FD9\u4E2A\u95EE\u9898;\u6211\u4EEC\u53EA\u9700\u8981\u7528\u4E00\u4E2A\u7279\u6B8A\u7684tokenizer\u3002"),xa=f(),ze=o("p"),$t=t("\u9996\u5148\uFF0C\u8BA9\u6211\u4EEC\u521B\u5EFA"),ya=o("code"),Oa=t("tokenizer"),Xr=t("\u5BF9\u8C61\u3002\u5982\u524D\u6240\u8FF0\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 BERT \u9884\u8BAD\u7EC3\u6A21\u578B\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4ECE\u4E0B\u8F7D\u5E76\u7F13\u5B58\u5173\u8054\u7684\u5206\u8BCD\u5668\u5F00\u59CB\uFF1A"),cr=f(),w(kt.$$.fragment),Je=f(),Ce=o("p"),Ca=t("\u4F60\u53EF\u4EE5\u66F4\u6362\u628A "),qa=o("code"),Zr=t("model_checkpoint"),Ta=t(" \u66F4\u6362\u4E3A "),jt=o("a"),Kr=t("Hub"),Da=t(",\u4E0A\u60A8\u559C\u6B22\u7684\u4EFB\u4F55\u5176\u4ED6\u578B\u53F7\uFF0C\u6216\u4F7F\u7528\u60A8\u672C\u5730\u4FDD\u5B58\u7684\u9884\u8BAD\u7EC3\u6A21\u578B\u548C\u5206\u8BCD\u5668\u3002\u552F\u4E00\u7684\u9650\u5236\u662F\u5206\u8BCD\u5668\u9700\u8981\u7531 \u{1F917} Tokenizers \u5E93\u652F\u6301\uFF0C\u6709\u4E00\u4E2A\u201C\u5FEB\u901F\u201D\u7248\u672C\u53EF\u7528\u3002\u4F60\u53EF\u4EE5\u5728"),gt=o("a"),Vr=t("\u8FD9\u5F20\u5927\u8868"),Pa=t(", \u4E0A\u770B\u5230\u6240\u6709\u5E26\u6709\u5FEB\u901F\u7248\u672C\u7684\u67B6\u6784\uFF0C\u6216\u8005\u68C0\u67E5  \u60A8\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u5B83"),za=o("code"),Yr=t("is_fast"),Jr=t(" \u5C5E\u6027\u6765\u68C0\u6D4B\u6B63\u5728\u4F7F\u7528\u7684"),zs=o("code"),Qr=t("tokenizer"),Aa=t("\u5BF9\u8C61\u662F\u5426\u7531 \u{1F917} Tokenizers \u652F\u6301\uFF1A"),fr=f(),w(vt.$$.fragment),Kt=f(),w(wt.$$.fragment),mr=f(),As=o("p"),Vt=t("\u8981\u5BF9\u9884\u5148\u6807\u8BB0\u7684\u8F93\u5165\u8FDB\u884C\u6807\u8BB0\uFF0C\u6211\u4EEC\u53EF\u4EE5\u50CF\u5F80\u5E38\u4E00\u6837\u4F7F\u7528\u6211\u4EEC\u7684"),Ia=o("code"),ur=t("tokenizer"),Et=t(" \u53EA\u9700\u6DFB\u52A0 "),Yt=o("code"),Jt=t("is_split_into_words=True"),en=t(":"),Ra=f(),w(Is.$$.fragment),Sa=f(),w(oe.$$.fragment),_r=f(),me=o("p"),sn=t("\u6B63\u5982\u6211\u4EEC\u6240\u89C1\uFF0C\u5206\u8BCD\u5668\u6DFB\u52A0\u4E86\u6A21\u578B\u4F7F\u7528\u7684\u7279\u6B8AToken("),Ba=o("code"),Na=t("[CLS]"),ln=t(" \u5728\u5F00\u59CB\u548C"),La=o("code"),Fa=t("[SEP]"),tn=t(" \u6700\u540E) \u800C\u5927\u591A\u6570\u5355\u8BCD\u672A\u88AB\u4FEE\u6539\u3002\u7136\u800C\uFF0C\u5355\u8BCD "),Ma=o("code"),Ha=t("lamb"),an=t(",\u88AB\u5206\u4E3A\u4E24\u4E2A\u5B50\u5355\u8BCD "),Ga=o("code"),Ua=t("la"),rn=t(" and "),Wa=o("code"),Xa=t("##mb"),nn=t(`\u3002\u8FD9\u5BFC\u81F4\u4E86\u8F93\u5165\u548C\u6807\u7B7E\u4E4B\u95F4\u7684\u4E0D\u5339\u914D:\u6807\u7B7E\u5217\u8868\u53EA\u67099\u4E2A\u5143\u7D20\uFF0C\u800C\u6211\u4EEC\u7684\u8F93\u5165\u73B0\u5728\u670912\u4E2Atoken \u3002\u8BA1\u7B97\u7279\u6B8AToken\u5F88\u5BB9\u6613(\u6211\u4EEC\u77E5\u9053\u5B83\u4EEC\u5728\u5F00\u5934\u548C\u7ED3\u5C3E)\uFF0C\u4F46\u6211\u4EEC\u8FD8\u9700\u8981\u786E\u4FDD\u6240\u6709\u6807\u7B7E\u4E0E\u9002\u5F53\u7684\u5355\u8BCD\u5BF9\u9F50\u3002
\u5E78\u8FD0\u7684\u662F\uFF0C\u7531\u4E8E\u6211\u4EEC\u4F7F\u7528\u7684\u662F\u5FEB\u901F\u5206\u8BCD\u5668\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u8BBF\u95EE\u{1F917} Tokenizers\u8D85\u80FD\u529B\uFF0C\u8FD9\u610F\u5473\u7740\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u5730\u5C06\u6BCF\u4E2A\u4EE4\u724C\u6620\u5C04\u5230\u5176\u76F8\u5E94\u7684\u5355\u8BCD\uFF08\u5982`),Qt=o("a"),Za=t("Chapter 6"),on=t("):"),dr=f(),w(Kl.$$.fragment),Rs=f(),w(xt.$$.fragment),ea=f(),Qe=o("p"),pn=t("\u901A\u8FC7\u4E00\u70B9\u70B9\u5DE5\u4F5C\uFF0C\u6211\u4EEC\u53EF\u4EE5\u6269\u5C55\u6211\u4EEC\u7684\u6807\u7B7E\u5217\u8868\u4EE5\u5339\u914Dtoken \u3002\u6211\u4EEC\u5C06\u5E94\u7528\u7684\u7B2C\u4E00\u6761\u89C4\u5219\u662F\uFF0C\u7279\u6B8Atoken \u7684\u6807\u7B7E\u4E3A "),yl=o("code"),cn=t("-100"),fn=t(" \u3002\u8FD9\u662F\u56E0\u4E3A\u9ED8\u8BA4\u60C5\u51B5\u4E0B "),sa=o("code"),r=t("-100"),h=t(" \u662F\u4E00\u4E2A\u5728\u6211\u4EEC\u5C06\u4F7F\u7528\u7684\u635F\u5931\u51FD\u6570\uFF08\u4EA4\u53C9\u71B5\uFF09\u4E2D\u88AB\u5FFD\u7565\u7684\u7D22\u5F15\u3002\u7136\u540E\uFF0C\u6BCF\u4E2Atoken \u90FD\u4F1A\u83B7\u5F97\u4E0E\u5176\u6240\u5728\u5355\u8BCD\u7684token \u76F8\u540C\u7684\u6807\u7B7E\uFF0C\u56E0\u4E3A\u5B83\u4EEC\u662F\u540C\u4E00\u5B9E\u4F53\u7684\u4E00\u90E8\u5206\u3002\u5BF9\u4E8E\u5355\u8BCD\u5185\u90E8\u4F46\u4E0D\u5728\u5F00\u5934\u7684Token\uFF0C\u6211\u4EEC\u5C06"),Vl=o("code"),Fn=t("B-"),Mn=t(" \u66FF\u6362\u4E3A "),Yl=o("code"),Hn=t("I-"),Gn=t(" (\u56E0\u4E3Atoken \u4E0D\u4EE5\u5B9E\u4F53\u5F00\u5934):"),Ka=f(),w(la.$$.fragment),yt=f(),Va=o("p"),Un=t("\u8BA9\u6211\u4EEC\u5728\u6211\u4EEC\u7684\u7B2C\u4E00\u53E5\u8BDD\u4E0A\u8BD5\u4E00\u8BD5\uFF1A"),mn=f(),w(Jl.$$.fragment),un=f(),w(ta.$$.fragment),Ya=f(),Ol=o("p"),ks=t("\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u6211\u4EEC\u7684\u51FD\u6570\u4E3A\u5F00\u5934\u548C\u7ED3\u5C3E\u7684\u4E24\u4E2A\u7279\u6B8A\u6807\u8BB0\u6DFB\u52A0\u4E86  "),hr=o("code"),_n=t("-100"),Wn=t(" \uFF0C\u5E76\u4E3A\u5206\u6210\u4E24\u4E2A\u6807\u8BB0\u7684\u5355\u8BCD\u6DFB\u52A0\u4E86\u4E00\u4E2A\u65B0\u7684"),br=o("code"),Xn=t("0"),Zn=t(" \u3002"),Ja=f(),w(Ot.$$.fragment),dn=f(),Ae=o("p"),Kn=t("\u4E3A\u4E86\u9884\u5904\u7406\u6211\u4EEC\u7684\u6574\u4E2A\u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u9700\u8981\u6807\u8BB0\u6240\u6709\u8F93\u5165\u5E76\u5728\u6240\u6709\u6807\u7B7E\u4E0A\u5E94\u7528 "),$r=o("code"),kr=t("align_labels_with_tokens()"),Vn=t(" \u3002\u4E3A\u4E86\u5229\u7528\u6211\u4EEC\u7684\u5FEB\u901F\u5206\u8BCD\u5668\u7684\u901F\u5EA6\u4F18\u52BF\uFF0C\u6700\u597D\u540C\u65F6\u5BF9\u5927\u91CF\u6587\u672C\u8FDB\u884C\u5206\u8BCD\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u7F16\u5199\u4E00\u4E2A\u5904\u7406\u793A\u4F8B\u5217\u8868\u7684\u51FD\u6570\u5E76\u4F7F\u7528\u5E26 "),jr=o("code"),Yn=t("batched=True"),gr=t(" \u6709\u9009\u9879\u7684 "),vr=o("code"),Jn=t("Dataset.map()"),Qn=t("\u65B9\u6CD5 .\u4E0E\u6211\u4EEC\u4E4B\u524D\u7684\u793A\u4F8B\u552F\u4E00\u4E0D\u540C\u7684\u662F\u5F53\u5206\u8BCD\u5668\u7684\u8F93\u5165\u662F\u6587\u672C\u5217\u8868\uFF08\u6216\u8005\u50CF\u4F8B\u5B50\u4E2D\u7684\u5355\u8BCD\u5217\u8868\uFF09\u65F6  "),Ql=o("code"),eo=t("word_ids()"),so=t(" \u51FD\u6570\u9700\u8981\u83B7\u53D6\u6211\u4EEC\u60F3\u8981\u5355\u8BCD\u7684\u7D22\u5F15\u7684ID\uFF0C\u6240\u4EE5\u6211\u4EEC\u4E5F\u6DFB\u52A0\u5B83\uFF1A"),Qa=f(),w(aa.$$.fragment),Ct=f(),er=o("p"),lo=t("\u8BF7\u6CE8\u610F\uFF0C\u6211\u4EEC\u8FD8\u6CA1\u6709\u586B\u5145\u6211\u4EEC\u7684\u8F93\u5165\uFF1B\u6211\u4EEC\u7A0D\u540E\u4F1A\u5728\u4F7F\u7528\u6570\u636E\u6574\u7406\u5668\u521B\u5EFAbatch\u65F6\u8FD9\u6837\u505A\u3002"),Cl=f(),sr=o("p"),to=t("\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u4E00\u6B21\u6027\u5C06\u6240\u6709\u9884\u5904\u7406\u5E94\u7528\u4E8E\u6570\u636E\u96C6\u7684\u5176\u4ED6\u90E8\u5206\uFF1A"),hn=f(),w(ra.$$.fragment),qt=f(),Tt=o("p"),ao=t("\u6211\u4EEC\u5DF2\u7ECF\u5B8C\u6210\u4E86\u6700\u96BE\u7684\u90E8\u5206\uFF01\u73B0\u5728\u6570\u636E\u5DF2\u7ECF\u88AB\u9884\u5904\u7406\u4E86\uFF0C\u5B9E\u9645\u7684\u8BAD\u7EC3\u770B\u8D77\u6765\u5F88\u50CF\u6211\u4EEC"),Dt=o("a"),ro=t("\u7B2C\u4E09\u7AE0"),no=t("\u505A\u7684."),bn=f(),tl.c(),ql=f(),et=o("h3"),oo=t("\u6570\u636E\u6392\u5E8F"),Ss=f(),Bs=o("p"),po=t("\u6211\u4EEC\u4E0D\u80FD\u50CF"),lr=o("a"),io=t("\u7B2C\u4E09\u7AE0"),na=t("\u90A3\u6837\u53EA\u4F7F\u7528\u4E00\u4E2A "),wr=o("code"),co=t("DataCollatorWithPadding "),fo=t("\u56E0\u4E3A\u8FD9\u53EA\u4F1A\u586B\u5145\u8F93\u5165\uFF08\u8F93\u5165 ID\u3001\u6CE8\u610F\u63A9\u7801\u548C\u6807\u8BB0\u7C7B\u578B ID\uFF09\u3002\u5728\u8FD9\u91CC\u6211\u4EEC\u7684\u6807\u7B7E\u5E94\u8BE5\u4EE5\u4E0E\u8F93\u5165\u5B8C\u5168\u76F8\u540C\u7684\u65B9\u5F0F\u586B\u5145\uFF0C\u4EE5\u4FBF\u5B83\u4EEC\u4FDD\u6301\u957F\u5EA6\u76F8\u540C\uFF0C\u4F7F\u7528  "),Er=o("code"),qe=t("-100"),mo=t(" \uFF0C\u8FD9\u6837\u5728\u635F\u5931\u8BA1\u7B97\u4E2D\u5C31\u53EF\u4EE5\u5FFD\u7565\u76F8\u5E94\u7684\u9884\u6D4B\u3002"),$n=f(),Tl=o("p"),uo=t("\u8FD9\u4E00\u5207\u90FD\u662F\u7531\u4E00\u4E2A "),oa=o("a"),xr=o("code"),_o=t("DataCollatorForTokenClassification"),pa=t("\u5B8C\u6210.\u5B83\u662F\u4E00\u4E2A\u5E26\u6709\u586B\u5145\u7684\u6570\u636E\u6574\u7406\u5668\u5B83\u9700\u8981  "),yr=o("code"),ho=t("tokenizer"),xp=t(" \u7528\u4E8E\u9884\u5904\u7406\u8F93\u5165\uFF1A"),Wo=f(),zt.c(),bo=f(),$o=o("p"),yp=t("\u4E3A\u4E86\u5728\u51E0\u4E2A\u6837\u672C\u4E0A\u6D4B\u8BD5\u8FD9\u4E00\u70B9\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5728\u8BAD\u7EC3\u96C6\u4E2D\u7684\u793A\u4F8B\u5217\u8868\u4E0A\u8C03\u7528\u5B83\uFF1A"),Xo=f(),w(kn.$$.fragment),Zo=f(),w(jn.$$.fragment),Ko=f(),ko=o("p"),Op=t("\u8BA9\u6211\u4EEC\u5C06\u5176\u4E0E\u6570\u636E\u96C6\u4E2D\u7B2C\u4E00\u4E2A\u548C\u7B2C\u4E8C\u4E2A\u5143\u7D20\u7684\u6807\u7B7E\u8FDB\u884C\u6BD4\u8F83\uFF1A"),Vo=f(),w(gn.$$.fragment),Yo=f(),w(vn.$$.fragment),Jo=f(),It.c(),jo=f(),Ie&&Ie.c(),go=f(),wn=o("h3"),Cp=t("\u8BC4\u4F30\u6307\u6807"),Qo=f(),St.c(),vo=f(),w(En.$$.fragment),ep=f(),wo=o("p"),qp=t("\u8FD9\u4E2A\u8BC4\u4F30\u65B9\u5F0F\u4E0E\u6807\u51C6\u7CBE\u5EA6\u4E0D\u540C:\u5B83\u5B9E\u9645\u4E0A\u5C06\u6807\u7B7E\u5217\u8868\u4F5C\u4E3A\u5B57\u7B26\u4E32\uFF0C\u800C\u4E0D\u662F\u6574\u6570\uFF0C\u56E0\u6B64\u5728\u5C06\u9884\u6D4B\u548C\u6807\u7B7E\u4F20\u9012\u7ED9\u5B83\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5B8C\u5168\u89E3\u7801\u5B83\u4EEC\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u5B83\u662F\u5982\u4F55\u5DE5\u4F5C\u7684\u3002\u9996\u5148\uFF0C\u6211\u4EEC\u5C06\u83B7\u5F97\u7B2C\u4E00\u4E2A\u8BAD\u7EC3\u793A\u4F8B\u7684\u6807\u7B7E:"),sp=f(),w(xn.$$.fragment),lp=f(),w(yn.$$.fragment),tp=f(),Eo=o("p"),Tp=t("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u66F4\u6539\u7D22\u5F15 2 \u5904\u7684\u503C\u6765\u4E3A\u90A3\u4E9B\u521B\u5EFA\u5047\u7684\u9884\u6D4B\uFF1A"),ap=f(),w(On.$$.fragment),rp=f(),xo=o("p"),Dp=t("\u8BF7\u6CE8\u610F\uFF0C\u8BE5\u6307\u6807\u7684\u8F93\u5165\u662F\u9884\u6D4B\u5217\u8868\uFF08\u4E0D\u4EC5\u4EC5\u662F\u4E00\u4E2A\uFF09\u548C\u6807\u7B7E\u5217\u8868\u3002\u8FD9\u662F\u8F93\u51FA\uFF1A"),np=f(),w(Cn.$$.fragment),op=f(),Nt.c(),yo=f(),Re&&Re.c(),Oo=f(),qn=o("h2"),Pp=t("\u4F7F\u7528\u5FAE\u8C03\u6A21\u578B"),pp=f(),Or=o("p"),zp=t("\u6211\u4EEC\u5DF2\u7ECF\u5411\u60A8\u5C55\u793A\u4E86\u5982\u4F55\u4F7F\u7528\u6211\u4EEC\u5728\u6A21\u578B\u4E2D\u5FC3\u5FAE\u8C03\u7684\u6A21\u578B\u548C\u63A8\u7406\u5C0F\u90E8\u4EF6\u3002\u5728\u672C\u5730\u4F7F\u7528\u5B83 "),So=o("code"),Ap=t("pipeline"),Ip=t(" \uFF0C\u60A8\u53EA\u9700\u8981\u6307\u5B9A\u6B63\u786E\u7684\u6A21\u578B\u6807\u8BC6\u7B26\uFF1A"),ip=f(),w(Tn.$$.fragment),cp=f(),w(Dn.$$.fragment),fp=f(),Co=o("p"),Rp=t("\u592A\u68D2\u4E86\uFF01\u6211\u4EEC\u7684\u6A21\u578B\u4E0E\u6B64\u7BA1\u9053\u7684\u9ED8\u8BA4\u6A21\u578B\u4E00\u6837\u6709\u6548\uFF01"),this.h()},l(e){const c=Tc('[data-svelte="svelte-1phssyn"]',document.head);u=p(c,"META",{name:!0,content:!0}),c.forEach(s),j=m(e),E(d.$$.fragment,e),$=m(e),q=p(e,"H1",{class:!0});var Bn=i(q);v=p(Bn,"A",{id:!0,class:!0,href:!0});var qo=i(v);b=p(qo,"SPAN",{});var Bo=i(b);E(T.$$.fragment,Bo),Bo.forEach(s),qo.forEach(s),S=m(Bn),R=p(Bn,"SPAN",{});var No=i(R);H=a(No,"Token \u5206\u7C7B"),No.forEach(s),Bn.forEach(s),A=m(e),M.l(e),C=m(e),N=p(e,"P",{});var Lo=i(N);K=a(Lo,"\u6211\u4EEC\u5C06\u63A2\u7D22\u7684\u7B2C\u4E00\u4E2A\u5E94\u7528\u662FToken\u5206\u7C7B\u3002\u8FD9\u4E2A\u901A\u7528\u4EFB\u52A1\u5305\u62EC\u4EFB\u4F55\u53EF\u4EE5\u8868\u8FF0\u4E3A\u201C\u4E3A\u53E5\u5B50\u4E2D\u7684\u8BCD\u6216\u5B57\u5206\u914D\u6807\u7B7E\u201D\u7684\u95EE\u9898\uFF0C\u4F8B\u5982\uFF1A"),Lo.forEach(s),X=m(e),z=p(e,"UL",{});var ia=i(z);W=p(ia,"LI",{});var Nn=i(W);G=p(Nn,"STRONG",{});var To=i(G);Q=a(To,"\u5B9E\u4F53\u547D\u540D\u8BC6\u522B (NER)"),To.forEach(s),Y=a(Nn,": \u627E\u51FA\u53E5\u5B50\u4E2D\u7684\u5B9E\u4F53\uFF08\u5982\u4EBA\u7269\u3001\u5730\u70B9\u6216\u7EC4\u7EC7\uFF09\u3002\u8FD9\u53EF\u4EE5\u901A\u8FC7\u4E3A\u6BCF\u4E2A\u5B9E\u4F53\u6216\u201C\u65E0\u5B9E\u4F53\u201D\u6307\u5B9A\u4E00\u4E2A\u7C7B\u522B\u7684\u6807\u7B7E\u3002"),Nn.forEach(s),V=m(ia),te=p(ia,"LI",{});var Ln=i(te);B=p(Ln,"STRONG",{});var Do=i(B);ee=a(Do,"\u8BCD\u6027\u6807\u6CE8 (POS)"),Do.forEach(s),U=a(Ln,": \u5C06\u53E5\u5B50\u4E2D\u7684\u6BCF\u4E2A\u5355\u8BCD\u6807\u8BB0\u4E3A\u5BF9\u5E94\u4E8E\u7279\u5B9A\u7684\u8BCD\u6027\uFF08\u5982\u540D\u8BCD\u3001\u52A8\u8BCD\u3001\u5F62\u5BB9\u8BCD\u7B49\uFF09\u3002"),Ln.forEach(s),Z=m(ia),L=p(ia,"LI",{});var Sp=i(L);se=p(Sp,"STRONG",{});var Yp=i(se);J=a(Yp,"\u5206\u5757\uFF08chunking\uFF09"),Yp.forEach(s),pe=a(Sp,": \u627E\u5230\u5C5E\u4E8E\u540C\u4E00\u5B9E\u4F53\u7684Token\u3002\u8FD9\u4E2A\u4EFB\u52A1(\u53EF\u7ED3\u5408POS\u6216NER)\u53EF\u4EE5\u4EFB\u4F55\u5C06\u4E00\u5757Token\u4F5C\u4E3A\u5236\u5B9A\u4E00\u4E2A\u6807\u7B7E(\u901A\u5E38\u662FB -),\u53E6\u4E00\u4E2A\u6807\u7B7E(\u901A\u5E38I -)\u8868\u793AToken\u662F\u5426\u662F\u540C\u4E00\u5757,\u548C\u7B2C\u4E09\u4E2A\u6807\u7B7E(\u901A\u5E38\u662FO)\u8868\u793AToken\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u5757\u3002\u4E5F\u5C31\u662F\u6807\u51FA\u53E5\u5B50\u4E2D\u7684\u77ED\u8BED\u5757\uFF0C\u4F8B\u5982\u540D\u8BCD\u77ED\u8BED\uFF08NP\uFF09\uFF0C\u52A8\u8BCD\u77ED\u8BED\uFF08VP\uFF09\u7B49\u3002"),Sp.forEach(s),ia.forEach(s),fe=m(e),E(ie.$$.fragment,e),Se=m(e),re=p(e,"P",{});var Jp=i(re);Ns=a(Jp,"\u5F53\u7136\uFF0C\u8FD8\u6709\u5F88\u591A\u5176\u4ED6\u7C7B\u578B\u7684token\u5206\u7C7B\u95EE\u9898\uFF1B\u8FD9\u4E9B\u53EA\u662F\u51E0\u4E2A\u6709\u4EE3\u8868\u6027\u7684\u4F8B\u5B50\u3002\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u5728 NER \u4EFB\u52A1\u4E0A\u5FAE\u8C03\u6A21\u578B (BERT)\uFF0C\u7136\u540E\u8BE5\u6A21\u578B\u5C06\u80FD\u591F\u8BA1\u7B97\u5982\u4E0B\u9884\u6D4B\uFF1A"),Jp.forEach(s),js=m(e),ue=p(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),i(ue).forEach(s),Ls=m(e),ae=p(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),i(ae).forEach(s),ke=m(e),je=p(e,"A",{class:!0,href:!0});var up=i(je);_e=p(up,"IMG",{class:!0,src:!0,alt:!0}),rl=m(up),de=p(up,"IMG",{class:!0,src:!0,alt:!0}),up.forEach(s),gs=m(e),ge=p(e,"P",{});var _p=i(ge);Pl=a(_p,"\u60A8\u53EF\u4EE5"),Te=p(_p,"A",{href:!0,rel:!0});var Qp=i(Te);vs=a(Qp,"\u5728\u8FD9\u91CC"),Qp.forEach(s),nl=a(_p,".\u627E\u5230\u6211\u4EEC\u5C06\u8BAD\u7EC3\u5E76\u4E0A\u4F20\u5230 Hub\u7684\u6A21\u578B\uFF0C\u53EF\u4EE5\u5C1D\u8BD5\u8F93\u5165\u4E00\u4E9B\u53E5\u5B50\u770B\u770B\u6A21\u578B\u7684\u9884\u6D4B\u7ED3\u679C\u3002"),_p.forEach(s),Ne=m(e),ws=p(e,"H2",{id:!0});var ei=i(ws);ol=a(ei,"\u51C6\u5907\u6570\u636E"),ei.forEach(s),ve=m(e),Le=p(e,"P",{});var dp=i(Le);ce=a(dp,"\u9996\u5148\uFF0C\u6211\u4EEC\u9700\u8981\u4E00\u4E2A\u9002\u5408\u6807\u8BB0\u5206\u7C7B\u7684\u6570\u636E\u96C6\u3002\u5728\u672C\u8282\u4E2D\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528"),Es=p(dp,"A",{href:!0,rel:!0});var si=i(Es);xs=a(si,"CoNLL-2003 \u6570\u636E\u96C6"),si.forEach(s),lt=a(dp,", \u5176\u4E2D\u5305\u542B\u6765\u81EA\u8DEF\u900F\u793E\u7684\u65B0\u95FB\u62A5\u9053\u3002"),dp.forEach(s),zl=m(e),E(De.$$.fragment,e),cs=m(e),Fe=p(e,"H3",{class:!0});var hp=i(Fe);le=p(hp,"A",{id:!0,class:!0,href:!0});var li=i(le);pl=p(li,"SPAN",{});var ti=i(pl);E(es.$$.fragment,ti),ti.forEach(s),li.forEach(s),Al=m(hp),ss=p(hp,"SPAN",{});var ai=i(ss);ls=a(ai,"CoNLL-2003 \u6570\u636E\u96C6"),ai.forEach(s),hp.forEach(s),he=m(e),fs=p(e,"P",{});var bp=i(fs);il=a(bp,"\u8981\u52A0\u8F7D CoNLL-2003 \u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u4F7F\u7528 \u6765\u81EA \u{1F917} Datasets \u5E93\u7684"),cl=p(bp,"STRONG",{});var ri=i(cl);fl=a(ri,"load_dataset()"),ri.forEach(s),ml=a(bp," \u65B9\u6CD5\uFF1A"),bp.forEach(s),Il=m(e),E(ts.$$.fragment,e),ul=m(e),be=p(e,"P",{});var $p=i(be);_l=a($p,"\u8FD9\u5C06\u4E0B\u8F7D\u5E76\u7F13\u5B58\u6570\u636E\u96C6\uFF0C\u5C31\u50CF\u548C\u6211\u4EEC\u5728"),ms=p($p,"A",{href:!0});var ni=i(ms);tt=a(ni,"\u7B2C\u4E09\u7AE0"),ni.forEach(s),Rl=a($p," \u52A0\u8F7DGLUE MRPC \u6570\u636E\u96C6\u4E00\u6837\u3002\u68C0\u67E5\u8FD9\u4E2A\u5BF9\u8C61\u53EF\u4EE5\u8BA9\u6211\u4EEC\u770B\u5230\u5B58\u5728\u54EA\u4E9B\u5217\uFF0C\u4EE5\u53CA\u8BAD\u7EC3\u96C6\u3001\u9A8C\u8BC1\u96C6\u548C\u6D4B\u8BD5\u96C6\u4E4B\u95F4\u662F\u5982\u4F55\u5206\u5272\u7684:"),$p.forEach(s),as=m(e),E(we.$$.fragment,e),Me=m(e),E(ne.$$.fragment,e),Fs=m(e),He=p(e,"P",{});var kp=i(He);at=a(kp,"\u7279\u522B\u662F\uFF0C\u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u6570\u636E\u96C6\u5305\u542B\u6211\u4EEC\u4E4B\u524D\u63D0\u5230\u7684\u4E09\u4E2A\u4EFB\u52A1\u7684\u6807\u7B7E\uFF1ANER\u3001POS \u548Cchunking\u3002\u4E0E\u5176\u4ED6\u6570\u636E\u96C6\u7684\u4E00\u4E2A\u5F88\u5927\u533A\u522B\u662F\u8F93\u5165\u6587\u672C\u4E0D\u662F\u4F5C\u4E3A\u53E5\u5B50\u6216\u6587\u6863\u5448\u73B0\u7684\uFF0C\u800C\u662F\u5355\u8BCD\u5217\u8868\uFF08\u6700\u540E\u4E00\u5217\u79F0\u4E3A "),Ms=p(kp,"STRONG",{});var oi=i(Ms);Ee=a(oi,"tokens"),oi.forEach(s),Hs=a(kp," \uFF0C\u4F46\u5B83\u5305\u542B\u7684\u662F\u8FD9\u4E9B\u8BCD\u662F\u9884\u5148\u6807\u8BB0\u5316\u7684\u8F93\u5165\uFF0C\u4ECD\u7136\u9700\u8981\u901A\u8FC7\u6807\u8BB0\u5668\u8FDB\u884C\u5B50\u8BCD\u6807\u8BB0\uFF09\u3002"),kp.forEach(s),ys=m(e),Gs=p(e,"P",{});var pi=i(Gs);Sl=a(pi,"\u6211\u4EEC\u6765\u770B\u770B\u8BAD\u7EC3\u96C6\u7684\u7B2C\u4E00\u4E2A\u5143\u7D20\uFF1A"),pi.forEach(s),Pe=m(e),E(Os.$$.fragment,e),Us=m(e),E(rs.$$.fragment,e),Bl=m(e),Cs=p(e,"P",{});var ii=i(Cs);ns=a(ii,"\u7531\u4E8E\u6211\u4EEC\u8981\u6267\u884C\u547D\u540D\u5B9E\u4F53\u8BC6\u522B\uFF0C\u6211\u4EEC\u5C06\u67E5\u770B NER \u6807\u7B7E\uFF1A"),ii.forEach(s),dl=m(e),E(Ge.$$.fragment,e),hl=m(e),E(xe.$$.fragment,e),os=m(e),Ue=p(e,"P",{});var ci=i(Ue);us=a(ci,"\u8FD9\u4E00\u5217\u662F\u7C7B\u6807\u7B7E\u7684\u5E8F\u5217\u3002\u5143\u7D20\u7684\u7C7B\u578B\u5728ner_feature\u7684feature\u5C5E\u6027\u4E2D\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u8BE5\u7279\u6027\u7684names\u5C5E\u6027\u6765\u8BBF\u95EE\u540D\u79F0\u5217\u8868:"),ci.forEach(s),bl=m(e),E(ye.$$.fragment,e),Nl=m(e),E(_s.$$.fragment,e),_=m(e),D=p(e,"P",{});var ca=i(D);Ws=a(ca,"\u56E0\u6B64\uFF0C\u8FD9\u4E00\u5217\u5305\u542B\u7684\u5143\u7D20\u662FClassLabels\u7684\u5E8F\u5217\u3002\u5E8F\u5217\u5143\u7D20\u7684\u7C7B\u578B\u5728"),$l=p(ca,"CODE",{});var fi=i($l);Xs=a(fi,"ner_feature"),fi.forEach(s),Zs=a(ca,"\u7684"),kl=p(ca,"CODE",{});var mi=i(kl);qs=a(mi,"feature"),mi.forEach(s),Ll=a(ca,"\u4E2D\uFF0C\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u8BE5"),Ts=p(ca,"CODE",{});var ui=i(Ts);Ks=a(ui,"feature"),ui.forEach(s),Mt=a(ca,"\u7684"),jl=p(ca,"CODE",{});var _i=i(jl);Vs=a(_i,"names"),_i.forEach(s),Ht=a(ca,"\u5C5E\u6027\u6765\u8BBF\u95EE\u540D\u79F0\u5217\u8868:"),ca.forEach(s),Fl=m(e),E(We.$$.fragment,e),Xe=m(e),E(ps.$$.fragment,e),rt=m(e),Ze=p(e,"P",{});var Po=i(Ze);Ke=a(Po,"\u6211\u4EEC\u5728"),Ys=p(Po,"A",{href:!0});var di=i(Ys);is=a(di,"\u7B2C\u516D\u7AE0"),di.forEach(s),Ml=a(Po,", \u6DF1\u5165\u7814\u7A76"),Js=p(Po,"STRONG",{});var hi=i(Js);Oe=a(hi,"token-classification"),hi.forEach(s),Gt=a(Po," \u7BA1\u9053\u65F6\u5DF2\u7ECF\u770B\u5230\u4E86\u8FD9\u4E9B\u6807\u7B7E \uFF0C\u4F46\u4E3A\u4E86\u5FEB\u901F\u590D\u4E60\uFF1A"),Po.forEach(s),Qs=m(e),$e=p(e,"UL",{});var fa=i($e);gl=p(fa,"LI",{});var Bp=i(gl);vl=p(Bp,"CODE",{});var bi=i(vl);el=a(bi,"O"),bi.forEach(s),nt=a(Bp," \u8868\u793A\u8FD9\u4E2A\u8BCD\u4E0D\u5BF9\u5E94\u4EFB\u4F55\u5B9E\u4F53\u3002"),Bp.forEach(s),Ds=m(fa),Hl=p(fa,"LI",{});var Fo=i(Hl);ot=p(Fo,"CODE",{});var $i=i(ot);Pr=a($i,"B-PER"),$i.forEach(s),zr=a(Fo,"/"),Ut=p(Fo,"CODE",{});var ki=i(Ut);pt=a(ki,"I-PER"),ki.forEach(s),tr=a(Fo,"\u610F\u5473\u7740\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u4EBA\u540D\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Fo.forEach(s),it=m(fa),wl=p(fa,"LI",{});var Mo=i(wl);ds=p(Mo,"CODE",{});var ji=i(ds);Ar=a(ji,"B-ORG"),ji.forEach(s),_a=a(Mo,"/"),da=p(Mo,"CODE",{});var gi=i(da);Ir=a(gi,"I-ORG"),gi.forEach(s),ha=a(Mo," \u7684\u610F\u601D\u662F\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u7EC4\u7EC7\u540D\u79F0\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Mo.forEach(s),Rr=m(fa),Gl=p(fa,"LI",{});var Ho=i(Gl);Wt=p(Ho,"CODE",{});var vi=i(Wt);ct=a(vi,"B-LOC"),vi.forEach(s),ar=a(Ho,"/"),Ve=p(Ho,"CODE",{});var wi=i(Ve);Sr=a(wi,"I-LOC"),wi.forEach(s),ba=a(Ho," \u6307\u7684\u662F\u662F\u8FD9\u4E2A\u8BCD\u5BF9\u5E94\u4E8E\u5730\u540D\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Ho.forEach(s),Br=m(fa),Ul=p(fa,"LI",{});var Go=i(Ul);ft=p(Go,"CODE",{});var Ei=i(ft);Nr=a(Ei,"B-MISC"),Ei.forEach(s),Lr=a(Go,"/"),mt=p(Go,"CODE",{});var xi=i(mt);Fr=a(xi,"I-MISC"),xi.forEach(s),Mr=a(Go," \u8868\u793A\u8BE5\u8BCD\u5BF9\u5E94\u4E8E\u4E00\u4E2A\u6742\u9879\u5B9E\u4F53\u7684\u5F00\u5934/\u5185\u90E8\u3002"),Go.forEach(s),fa.forEach(s),$a=m(e),sl=p(e,"P",{});var yi=i(sl);rr=a(yi,"\u73B0\u5728\u89E3\u7801\u6211\u4EEC\u4E4B\u524D\u770B\u5230\u7684\u6807\u7B7E\uFF1A"),yi.forEach(s),Wl=m(e),E(Xl.$$.fragment,e),ut=m(e),E(_t.$$.fragment,e),ka=m(e),Ye=p(e,"P",{});var zo=i(Ye);nr=a(zo,"\u4F8B\u5982\u6DF7\u5408 "),hs=p(zo,"STRONG",{});var Oi=i(hs);Hr=a(Oi,"B-"),Oi.forEach(s),ja=a(zo," \u548C "),ga=p(zo,"STRONG",{});var Ci=i(ga);Gr=a(Ci,"I-"),Ci.forEach(s),va=a(zo," \u6807\u7B7E\uFF0C\u8FD9\u662F\u76F8\u540C\u7684\u4EE3\u7801\u5728\u7D22\u5F15 4 \u7684\u8BAD\u7EC3\u96C6\u5143\u7D20\u4E0A\u7684\u9884\u6D4B\u7ED3\u679C\uFF1A"),zo.forEach(s),or=m(e),E(dt.$$.fragment,e),wa=m(e),bs=p(e,"P",{});var qi=i(bs);Zl=a(qi,"\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u8DE8\u8D8A\u4E24\u4E2A\u5355\u8BCD\u7684\u5B9E\u4F53\uFF0C\u5982\u201CEuropean Union\u201D\u548C\u201CWerner Zwingmann\u201D\uFF0C\u6A21\u578B\u4E3A\u7B2C\u4E00\u4E2A\u5355\u8BCD\u6807\u6CE8\u4E86\u4E00\u4E2AB-\u6807\u7B7E\uFF0C\u4E3A\u7B2C\u4E8C\u4E2A\u5355\u8BCD\u6807\u6CE8\u4E86\u4E00\u4E2AI-\u6807\u7B7E\u3002"),qi.forEach(s),Xt=m(e),E($s.$$.fragment,e),pr=m(e),El=p(e,"H3",{id:!0});var Ti=i(El);Ur=a(Ti,"\u5904\u7406\u6570\u636E"),Ti.forEach(s),Ea=m(e),E(Ps.$$.fragment,e),ir=m(e),xl=p(e,"P",{});var jp=i(xl);ht=a(jp,"\u50CF\u5F80\u5E38\u4E00\u6837\uFF0C\u6211\u4EEC\u7684\u6587\u672C\u9700\u8981\u8F6C\u6362\u4E3AToken ID\uFF0C\u7136\u540E\u6A21\u578B\u624D\u80FD\u7406\u89E3\u5B83\u4EEC\u3002\u6B63\u5982\u6211\u4EEC\u5728"),bt=p(jp,"A",{href:!0});var Di=i(bt);Zt=a(Di,"\u7B2C\u516D\u7AE0"),Di.forEach(s),Wr=a(jp,"\u6240\u5B66\u7684\u90A3\u6837\u3002\u4E0D\u8FC7\u5728\u6807\u8BB0\u4EFB\u52A1\u4E2D\uFF0C\u4E00\u4E2A\u5F88\u5927\u7684\u533A\u522B\u662F\u6211\u4EEC\u6709pre-tokenized\u7684\u8F93\u5165\u3002\u5E78\u8FD0\u7684\u662F\uFF0Ctokenizer API\u53EF\u4EE5\u5F88\u5BB9\u6613\u5730\u5904\u7406\u8FD9\u4E2A\u95EE\u9898;\u6211\u4EEC\u53EA\u9700\u8981\u7528\u4E00\u4E2A\u7279\u6B8A\u7684tokenizer\u3002"),jp.forEach(s),xa=m(e),ze=p(e,"P",{});var gp=i(ze);$t=a(gp,"\u9996\u5148\uFF0C\u8BA9\u6211\u4EEC\u521B\u5EFA"),ya=p(gp,"CODE",{});var Pi=i(ya);Oa=a(Pi,"tokenizer"),Pi.forEach(s),Xr=a(gp,"\u5BF9\u8C61\u3002\u5982\u524D\u6240\u8FF0\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 BERT \u9884\u8BAD\u7EC3\u6A21\u578B\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u4ECE\u4E0B\u8F7D\u5E76\u7F13\u5B58\u5173\u8054\u7684\u5206\u8BCD\u5668\u5F00\u59CB\uFF1A"),gp.forEach(s),cr=m(e),E(kt.$$.fragment,e),Je=m(e),Ce=p(e,"P",{});var st=i(Ce);Ca=a(st,"\u4F60\u53EF\u4EE5\u66F4\u6362\u628A "),qa=p(st,"CODE",{});var zi=i(qa);Zr=a(zi,"model_checkpoint"),zi.forEach(s),Ta=a(st," \u66F4\u6362\u4E3A "),jt=p(st,"A",{href:!0,rel:!0});var Ai=i(jt);Kr=a(Ai,"Hub"),Ai.forEach(s),Da=a(st,",\u4E0A\u60A8\u559C\u6B22\u7684\u4EFB\u4F55\u5176\u4ED6\u578B\u53F7\uFF0C\u6216\u4F7F\u7528\u60A8\u672C\u5730\u4FDD\u5B58\u7684\u9884\u8BAD\u7EC3\u6A21\u578B\u548C\u5206\u8BCD\u5668\u3002\u552F\u4E00\u7684\u9650\u5236\u662F\u5206\u8BCD\u5668\u9700\u8981\u7531 \u{1F917} Tokenizers \u5E93\u652F\u6301\uFF0C\u6709\u4E00\u4E2A\u201C\u5FEB\u901F\u201D\u7248\u672C\u53EF\u7528\u3002\u4F60\u53EF\u4EE5\u5728"),gt=p(st,"A",{href:!0,rel:!0});var Ii=i(gt);Vr=a(Ii,"\u8FD9\u5F20\u5927\u8868"),Ii.forEach(s),Pa=a(st,", \u4E0A\u770B\u5230\u6240\u6709\u5E26\u6709\u5FEB\u901F\u7248\u672C\u7684\u67B6\u6784\uFF0C\u6216\u8005\u68C0\u67E5  \u60A8\u53EF\u4EE5\u901A\u8FC7\u67E5\u770B\u5B83"),za=p(st,"CODE",{});var Ri=i(za);Yr=a(Ri,"is_fast"),Ri.forEach(s),Jr=a(st," \u5C5E\u6027\u6765\u68C0\u6D4B\u6B63\u5728\u4F7F\u7528\u7684"),zs=p(st,"CODE",{});var Si=i(zs);Qr=a(Si,"tokenizer"),Si.forEach(s),Aa=a(st,"\u5BF9\u8C61\u662F\u5426\u7531 \u{1F917} Tokenizers \u652F\u6301\uFF1A"),st.forEach(s),fr=m(e),E(vt.$$.fragment,e),Kt=m(e),E(wt.$$.fragment,e),mr=m(e),As=p(e,"P",{});var Ao=i(As);Vt=a(Ao,"\u8981\u5BF9\u9884\u5148\u6807\u8BB0\u7684\u8F93\u5165\u8FDB\u884C\u6807\u8BB0\uFF0C\u6211\u4EEC\u53EF\u4EE5\u50CF\u5F80\u5E38\u4E00\u6837\u4F7F\u7528\u6211\u4EEC\u7684"),Ia=p(Ao,"CODE",{});var Bi=i(Ia);ur=a(Bi,"tokenizer"),Bi.forEach(s),Et=a(Ao," \u53EA\u9700\u6DFB\u52A0 "),Yt=p(Ao,"CODE",{});var Ni=i(Yt);Jt=a(Ni,"is_split_into_words=True"),Ni.forEach(s),en=a(Ao,":"),Ao.forEach(s),Ra=m(e),E(Is.$$.fragment,e),Sa=m(e),E(oe.$$.fragment,e),_r=m(e),me=p(e,"P",{});var al=i(me);sn=a(al,"\u6B63\u5982\u6211\u4EEC\u6240\u89C1\uFF0C\u5206\u8BCD\u5668\u6DFB\u52A0\u4E86\u6A21\u578B\u4F7F\u7528\u7684\u7279\u6B8AToken("),Ba=p(al,"CODE",{});var Li=i(Ba);Na=a(Li,"[CLS]"),Li.forEach(s),ln=a(al," \u5728\u5F00\u59CB\u548C"),La=p(al,"CODE",{});var Fi=i(La);Fa=a(Fi,"[SEP]"),Fi.forEach(s),tn=a(al," \u6700\u540E) \u800C\u5927\u591A\u6570\u5355\u8BCD\u672A\u88AB\u4FEE\u6539\u3002\u7136\u800C\uFF0C\u5355\u8BCD "),Ma=p(al,"CODE",{});var Mi=i(Ma);Ha=a(Mi,"lamb"),Mi.forEach(s),an=a(al,",\u88AB\u5206\u4E3A\u4E24\u4E2A\u5B50\u5355\u8BCD "),Ga=p(al,"CODE",{});var Hi=i(Ga);Ua=a(Hi,"la"),Hi.forEach(s),rn=a(al," and "),Wa=p(al,"CODE",{});var Gi=i(Wa);Xa=a(Gi,"##mb"),Gi.forEach(s),nn=a(al,`\u3002\u8FD9\u5BFC\u81F4\u4E86\u8F93\u5165\u548C\u6807\u7B7E\u4E4B\u95F4\u7684\u4E0D\u5339\u914D:\u6807\u7B7E\u5217\u8868\u53EA\u67099\u4E2A\u5143\u7D20\uFF0C\u800C\u6211\u4EEC\u7684\u8F93\u5165\u73B0\u5728\u670912\u4E2Atoken \u3002\u8BA1\u7B97\u7279\u6B8AToken\u5F88\u5BB9\u6613(\u6211\u4EEC\u77E5\u9053\u5B83\u4EEC\u5728\u5F00\u5934\u548C\u7ED3\u5C3E)\uFF0C\u4F46\u6211\u4EEC\u8FD8\u9700\u8981\u786E\u4FDD\u6240\u6709\u6807\u7B7E\u4E0E\u9002\u5F53\u7684\u5355\u8BCD\u5BF9\u9F50\u3002
\u5E78\u8FD0\u7684\u662F\uFF0C\u7531\u4E8E\u6211\u4EEC\u4F7F\u7528\u7684\u662F\u5FEB\u901F\u5206\u8BCD\u5668\uFF0C\u56E0\u6B64\u6211\u4EEC\u53EF\u4EE5\u8BBF\u95EE\u{1F917} Tokenizers\u8D85\u80FD\u529B\uFF0C\u8FD9\u610F\u5473\u7740\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u5730\u5C06\u6BCF\u4E2A\u4EE4\u724C\u6620\u5C04\u5230\u5176\u76F8\u5E94\u7684\u5355\u8BCD\uFF08\u5982`),Qt=p(al,"A",{href:!0});var Ui=i(Qt);Za=a(Ui,"Chapter 6"),Ui.forEach(s),on=a(al,"):"),al.forEach(s),dr=m(e),E(Kl.$$.fragment,e),Rs=m(e),E(xt.$$.fragment,e),ea=m(e),Qe=p(e,"P",{});var ma=i(Qe);pn=a(ma,"\u901A\u8FC7\u4E00\u70B9\u70B9\u5DE5\u4F5C\uFF0C\u6211\u4EEC\u53EF\u4EE5\u6269\u5C55\u6211\u4EEC\u7684\u6807\u7B7E\u5217\u8868\u4EE5\u5339\u914Dtoken \u3002\u6211\u4EEC\u5C06\u5E94\u7528\u7684\u7B2C\u4E00\u6761\u89C4\u5219\u662F\uFF0C\u7279\u6B8Atoken \u7684\u6807\u7B7E\u4E3A "),yl=p(ma,"CODE",{});var Wi=i(yl);cn=a(Wi,"-100"),Wi.forEach(s),fn=a(ma," \u3002\u8FD9\u662F\u56E0\u4E3A\u9ED8\u8BA4\u60C5\u51B5\u4E0B "),sa=p(ma,"CODE",{});var Xi=i(sa);r=a(Xi,"-100"),Xi.forEach(s),h=a(ma," \u662F\u4E00\u4E2A\u5728\u6211\u4EEC\u5C06\u4F7F\u7528\u7684\u635F\u5931\u51FD\u6570\uFF08\u4EA4\u53C9\u71B5\uFF09\u4E2D\u88AB\u5FFD\u7565\u7684\u7D22\u5F15\u3002\u7136\u540E\uFF0C\u6BCF\u4E2Atoken \u90FD\u4F1A\u83B7\u5F97\u4E0E\u5176\u6240\u5728\u5355\u8BCD\u7684token \u76F8\u540C\u7684\u6807\u7B7E\uFF0C\u56E0\u4E3A\u5B83\u4EEC\u662F\u540C\u4E00\u5B9E\u4F53\u7684\u4E00\u90E8\u5206\u3002\u5BF9\u4E8E\u5355\u8BCD\u5185\u90E8\u4F46\u4E0D\u5728\u5F00\u5934\u7684Token\uFF0C\u6211\u4EEC\u5C06"),Vl=p(ma,"CODE",{});var Zi=i(Vl);Fn=a(Zi,"B-"),Zi.forEach(s),Mn=a(ma," \u66FF\u6362\u4E3A "),Yl=p(ma,"CODE",{});var Ki=i(Yl);Hn=a(Ki,"I-"),Ki.forEach(s),Gn=a(ma," (\u56E0\u4E3Atoken \u4E0D\u4EE5\u5B9E\u4F53\u5F00\u5934):"),ma.forEach(s),Ka=m(e),E(la.$$.fragment,e),yt=m(e),Va=p(e,"P",{});var Vi=i(Va);Un=a(Vi,"\u8BA9\u6211\u4EEC\u5728\u6211\u4EEC\u7684\u7B2C\u4E00\u53E5\u8BDD\u4E0A\u8BD5\u4E00\u8BD5\uFF1A"),Vi.forEach(s),mn=m(e),E(Jl.$$.fragment,e),un=m(e),E(ta.$$.fragment,e),Ya=m(e),Ol=p(e,"P",{});var Io=i(Ol);ks=a(Io,"\u6B63\u5982\u6211\u4EEC\u6240\u770B\u5230\u7684\uFF0C\u6211\u4EEC\u7684\u51FD\u6570\u4E3A\u5F00\u5934\u548C\u7ED3\u5C3E\u7684\u4E24\u4E2A\u7279\u6B8A\u6807\u8BB0\u6DFB\u52A0\u4E86  "),hr=p(Io,"CODE",{});var Yi=i(hr);_n=a(Yi,"-100"),Yi.forEach(s),Wn=a(Io," \uFF0C\u5E76\u4E3A\u5206\u6210\u4E24\u4E2A\u6807\u8BB0\u7684\u5355\u8BCD\u6DFB\u52A0\u4E86\u4E00\u4E2A\u65B0\u7684"),br=p(Io,"CODE",{});var Ji=i(br);Xn=a(Ji,"0"),Ji.forEach(s),Zn=a(Io," \u3002"),Io.forEach(s),Ja=m(e),E(Ot.$$.fragment,e),dn=m(e),Ae=p(e,"P",{});var ua=i(Ae);Kn=a(ua,"\u4E3A\u4E86\u9884\u5904\u7406\u6211\u4EEC\u7684\u6574\u4E2A\u6570\u636E\u96C6\uFF0C\u6211\u4EEC\u9700\u8981\u6807\u8BB0\u6240\u6709\u8F93\u5165\u5E76\u5728\u6240\u6709\u6807\u7B7E\u4E0A\u5E94\u7528 "),$r=p(ua,"CODE",{});var Qi=i($r);kr=a(Qi,"align_labels_with_tokens()"),Qi.forEach(s),Vn=a(ua," \u3002\u4E3A\u4E86\u5229\u7528\u6211\u4EEC\u7684\u5FEB\u901F\u5206\u8BCD\u5668\u7684\u901F\u5EA6\u4F18\u52BF\uFF0C\u6700\u597D\u540C\u65F6\u5BF9\u5927\u91CF\u6587\u672C\u8FDB\u884C\u5206\u8BCD\uFF0C\u56E0\u6B64\u6211\u4EEC\u5C06\u7F16\u5199\u4E00\u4E2A\u5904\u7406\u793A\u4F8B\u5217\u8868\u7684\u51FD\u6570\u5E76\u4F7F\u7528\u5E26 "),jr=p(ua,"CODE",{});var ec=i(jr);Yn=a(ec,"batched=True"),ec.forEach(s),gr=a(ua," \u6709\u9009\u9879\u7684 "),vr=p(ua,"CODE",{});var sc=i(vr);Jn=a(sc,"Dataset.map()"),sc.forEach(s),Qn=a(ua,"\u65B9\u6CD5 .\u4E0E\u6211\u4EEC\u4E4B\u524D\u7684\u793A\u4F8B\u552F\u4E00\u4E0D\u540C\u7684\u662F\u5F53\u5206\u8BCD\u5668\u7684\u8F93\u5165\u662F\u6587\u672C\u5217\u8868\uFF08\u6216\u8005\u50CF\u4F8B\u5B50\u4E2D\u7684\u5355\u8BCD\u5217\u8868\uFF09\u65F6  "),Ql=p(ua,"CODE",{});var lc=i(Ql);eo=a(lc,"word_ids()"),lc.forEach(s),so=a(ua," \u51FD\u6570\u9700\u8981\u83B7\u53D6\u6211\u4EEC\u60F3\u8981\u5355\u8BCD\u7684\u7D22\u5F15\u7684ID\uFF0C\u6240\u4EE5\u6211\u4EEC\u4E5F\u6DFB\u52A0\u5B83\uFF1A"),ua.forEach(s),Qa=m(e),E(aa.$$.fragment,e),Ct=m(e),er=p(e,"P",{});var tc=i(er);lo=a(tc,"\u8BF7\u6CE8\u610F\uFF0C\u6211\u4EEC\u8FD8\u6CA1\u6709\u586B\u5145\u6211\u4EEC\u7684\u8F93\u5165\uFF1B\u6211\u4EEC\u7A0D\u540E\u4F1A\u5728\u4F7F\u7528\u6570\u636E\u6574\u7406\u5668\u521B\u5EFAbatch\u65F6\u8FD9\u6837\u505A\u3002"),tc.forEach(s),Cl=m(e),sr=p(e,"P",{});var ac=i(sr);to=a(ac,"\u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u4E00\u6B21\u6027\u5C06\u6240\u6709\u9884\u5904\u7406\u5E94\u7528\u4E8E\u6570\u636E\u96C6\u7684\u5176\u4ED6\u90E8\u5206\uFF1A"),ac.forEach(s),hn=m(e),E(ra.$$.fragment,e),qt=m(e),Tt=p(e,"P",{});var vp=i(Tt);ao=a(vp,"\u6211\u4EEC\u5DF2\u7ECF\u5B8C\u6210\u4E86\u6700\u96BE\u7684\u90E8\u5206\uFF01\u73B0\u5728\u6570\u636E\u5DF2\u7ECF\u88AB\u9884\u5904\u7406\u4E86\uFF0C\u5B9E\u9645\u7684\u8BAD\u7EC3\u770B\u8D77\u6765\u5F88\u50CF\u6211\u4EEC"),Dt=p(vp,"A",{href:!0});var rc=i(Dt);ro=a(rc,"\u7B2C\u4E09\u7AE0"),rc.forEach(s),no=a(vp,"\u505A\u7684."),vp.forEach(s),bn=m(e),tl.l(e),ql=m(e),et=p(e,"H3",{id:!0});var nc=i(et);oo=a(nc,"\u6570\u636E\u6392\u5E8F"),nc.forEach(s),Ss=m(e),Bs=p(e,"P",{});var Cr=i(Bs);po=a(Cr,"\u6211\u4EEC\u4E0D\u80FD\u50CF"),lr=p(Cr,"A",{href:!0});var oc=i(lr);io=a(oc,"\u7B2C\u4E09\u7AE0"),oc.forEach(s),na=a(Cr,"\u90A3\u6837\u53EA\u4F7F\u7528\u4E00\u4E2A "),wr=p(Cr,"CODE",{});var pc=i(wr);co=a(pc,"DataCollatorWithPadding "),pc.forEach(s),fo=a(Cr,"\u56E0\u4E3A\u8FD9\u53EA\u4F1A\u586B\u5145\u8F93\u5165\uFF08\u8F93\u5165 ID\u3001\u6CE8\u610F\u63A9\u7801\u548C\u6807\u8BB0\u7C7B\u578B ID\uFF09\u3002\u5728\u8FD9\u91CC\u6211\u4EEC\u7684\u6807\u7B7E\u5E94\u8BE5\u4EE5\u4E0E\u8F93\u5165\u5B8C\u5168\u76F8\u540C\u7684\u65B9\u5F0F\u586B\u5145\uFF0C\u4EE5\u4FBF\u5B83\u4EEC\u4FDD\u6301\u957F\u5EA6\u76F8\u540C\uFF0C\u4F7F\u7528  "),Er=p(Cr,"CODE",{});var ic=i(Er);qe=a(ic,"-100"),ic.forEach(s),mo=a(Cr," \uFF0C\u8FD9\u6837\u5728\u635F\u5931\u8BA1\u7B97\u4E2D\u5C31\u53EF\u4EE5\u5FFD\u7565\u76F8\u5E94\u7684\u9884\u6D4B\u3002"),Cr.forEach(s),$n=m(e),Tl=p(e,"P",{});var Ro=i(Tl);uo=a(Ro,"\u8FD9\u4E00\u5207\u90FD\u662F\u7531\u4E00\u4E2A "),oa=p(Ro,"A",{href:!0,rel:!0});var cc=i(oa);xr=p(cc,"CODE",{});var fc=i(xr);_o=a(fc,"DataCollatorForTokenClassification"),fc.forEach(s),cc.forEach(s),pa=a(Ro,"\u5B8C\u6210.\u5B83\u662F\u4E00\u4E2A\u5E26\u6709\u586B\u5145\u7684\u6570\u636E\u6574\u7406\u5668\u5B83\u9700\u8981  "),yr=p(Ro,"CODE",{});var mc=i(yr);ho=a(mc,"tokenizer"),mc.forEach(s),xp=a(Ro," \u7528\u4E8E\u9884\u5904\u7406\u8F93\u5165\uFF1A"),Ro.forEach(s),Wo=m(e),zt.l(e),bo=m(e),$o=p(e,"P",{});var uc=i($o);yp=a(uc,"\u4E3A\u4E86\u5728\u51E0\u4E2A\u6837\u672C\u4E0A\u6D4B\u8BD5\u8FD9\u4E00\u70B9\uFF0C\u6211\u4EEC\u53EF\u4EE5\u5728\u8BAD\u7EC3\u96C6\u4E2D\u7684\u793A\u4F8B\u5217\u8868\u4E0A\u8C03\u7528\u5B83\uFF1A"),uc.forEach(s),Xo=m(e),E(kn.$$.fragment,e),Zo=m(e),E(jn.$$.fragment,e),Ko=m(e),ko=p(e,"P",{});var _c=i(ko);Op=a(_c,"\u8BA9\u6211\u4EEC\u5C06\u5176\u4E0E\u6570\u636E\u96C6\u4E2D\u7B2C\u4E00\u4E2A\u548C\u7B2C\u4E8C\u4E2A\u5143\u7D20\u7684\u6807\u7B7E\u8FDB\u884C\u6BD4\u8F83\uFF1A"),_c.forEach(s),Vo=m(e),E(gn.$$.fragment,e),Yo=m(e),E(vn.$$.fragment,e),Jo=m(e),It.l(e),jo=m(e),Ie&&Ie.l(e),go=m(e),wn=p(e,"H3",{id:!0});var dc=i(wn);Cp=a(dc,"\u8BC4\u4F30\u6307\u6807"),dc.forEach(s),Qo=m(e),St.l(e),vo=m(e),E(En.$$.fragment,e),ep=m(e),wo=p(e,"P",{});var hc=i(wo);qp=a(hc,"\u8FD9\u4E2A\u8BC4\u4F30\u65B9\u5F0F\u4E0E\u6807\u51C6\u7CBE\u5EA6\u4E0D\u540C:\u5B83\u5B9E\u9645\u4E0A\u5C06\u6807\u7B7E\u5217\u8868\u4F5C\u4E3A\u5B57\u7B26\u4E32\uFF0C\u800C\u4E0D\u662F\u6574\u6570\uFF0C\u56E0\u6B64\u5728\u5C06\u9884\u6D4B\u548C\u6807\u7B7E\u4F20\u9012\u7ED9\u5B83\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5B8C\u5168\u89E3\u7801\u5B83\u4EEC\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u5B83\u662F\u5982\u4F55\u5DE5\u4F5C\u7684\u3002\u9996\u5148\uFF0C\u6211\u4EEC\u5C06\u83B7\u5F97\u7B2C\u4E00\u4E2A\u8BAD\u7EC3\u793A\u4F8B\u7684\u6807\u7B7E:"),hc.forEach(s),sp=m(e),E(xn.$$.fragment,e),lp=m(e),E(yn.$$.fragment,e),tp=m(e),Eo=p(e,"P",{});var bc=i(Eo);Tp=a(bc,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u66F4\u6539\u7D22\u5F15 2 \u5904\u7684\u503C\u6765\u4E3A\u90A3\u4E9B\u521B\u5EFA\u5047\u7684\u9884\u6D4B\uFF1A"),bc.forEach(s),ap=m(e),E(On.$$.fragment,e),rp=m(e),xo=p(e,"P",{});var $c=i(xo);Dp=a($c,"\u8BF7\u6CE8\u610F\uFF0C\u8BE5\u6307\u6807\u7684\u8F93\u5165\u662F\u9884\u6D4B\u5217\u8868\uFF08\u4E0D\u4EC5\u4EC5\u662F\u4E00\u4E2A\uFF09\u548C\u6807\u7B7E\u5217\u8868\u3002\u8FD9\u662F\u8F93\u51FA\uFF1A"),$c.forEach(s),np=m(e),E(Cn.$$.fragment,e),op=m(e),Nt.l(e),yo=m(e),Re&&Re.l(e),Oo=m(e),qn=p(e,"H2",{id:!0});var kc=i(qn);Pp=a(kc,"\u4F7F\u7528\u5FAE\u8C03\u6A21\u578B"),kc.forEach(s),pp=m(e),Or=p(e,"P",{});var wp=i(Or);zp=a(wp,"\u6211\u4EEC\u5DF2\u7ECF\u5411\u60A8\u5C55\u793A\u4E86\u5982\u4F55\u4F7F\u7528\u6211\u4EEC\u5728\u6A21\u578B\u4E2D\u5FC3\u5FAE\u8C03\u7684\u6A21\u578B\u548C\u63A8\u7406\u5C0F\u90E8\u4EF6\u3002\u5728\u672C\u5730\u4F7F\u7528\u5B83 "),So=p(wp,"CODE",{});var jc=i(So);Ap=a(jc,"pipeline"),jc.forEach(s),Ip=a(wp," \uFF0C\u60A8\u53EA\u9700\u8981\u6307\u5B9A\u6B63\u786E\u7684\u6A21\u578B\u6807\u8BC6\u7B26\uFF1A"),wp.forEach(s),ip=m(e),E(Tn.$$.fragment,e),cp=m(e),E(Dn.$$.fragment,e),fp=m(e),Co=p(e,"P",{});var gc=i(Co);Rp=a(gc,"\u592A\u68D2\u4E86\uFF01\u6211\u4EEC\u7684\u6A21\u578B\u4E0E\u6B64\u7BA1\u9053\u7684\u9ED8\u8BA4\u6A21\u578B\u4E00\u6837\u6709\u6548\uFF01"),gc.forEach(s),this.h()},h(){O(u,"name","hf:doc:metadata"),O(u,"content",JSON.stringify(ef)),O(v,"id","token"),O(v,"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"),O(v,"href","#token"),O(q,"class","relative group"),Ep(ue.src,Be="https://hf.space/gradioiframe/course-demos/bert-finetuned-ner/+")||O(ue,"src",Be),O(ue,"frameborder","0"),O(ue,"height","350"),O(ue,"title","Gradio app"),O(ue,"class","block dark:hidden container p-0 flex-grow space-iframe"),O(ue,"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"),O(ue,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Ep(ae.src,Dl="https://hf.space/gradioiframe/course-demos/bert-finetuned-ner-darkmode/+")||O(ae,"src",Dl),O(ae,"frameborder","0"),O(ae,"height","350"),O(ae,"title","Gradio app"),O(ae,"class","hidden dark:block container p-0 flex-grow space-iframe"),O(ae,"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"),O(ae,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),O(_e,"class","block dark:hidden lg:w-3/5"),Ep(_e.src,Lt="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/model-eval-bert-finetuned-ner.png")||O(_e,"src",Lt),O(_e,"alt","One-hot encoded labels for question answering."),O(de,"class","hidden dark:block lg:w-3/5"),Ep(de.src,Ft="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/model-eval-bert-finetuned-ner-dark.png")||O(de,"src",Ft),O(de,"alt","One-hot encoded labels for question answering."),O(je,"class","flex justify-center"),O(je,"href","/huggingface-course/bert-finetuned-ner"),O(Te,"href","https://huggingface.co/huggingface-course/bert-finetuned-ner?text=My+name+is+Sylvain+and+I+work+at+Hugging+Face+in+Brooklyn"),O(Te,"rel","nofollow"),O(ws,"id",""),O(Es,"href","https://huggingface.co/datasets/conll2003"),O(Es,"rel","nofollow"),O(le,"id","conll2003"),O(le,"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"),O(le,"href","#conll2003"),O(Fe,"class","relative group"),O(ms,"href","/course/chapter3"),O(Ys,"href","/course/chapter6/3"),O(El,"id",""),O(bt,"href","/course/chapter6/"),O(jt,"href","https://huggingface.co/models"),O(jt,"rel","nofollow"),O(gt,"href","https://huggingface.co/transformers/#supported-frameworks"),O(gt,"rel","nofollow"),O(Qt,"href","/course/chapter6/3"),O(Dt,"href","/course/chapter3"),O(et,"id",""),O(lr,"href","/course/chapter3"),O(oa,"href","https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorfortokenclassification"),O(oa,"rel","nofollow"),O(wn,"id",""),O(qn,"id","")},m(e,c){l(document.head,u),n(e,j,c),x(d,e,c),n(e,$,c),n(e,q,c),l(q,v),l(v,b),x(T,b,null),l(q,S),l(q,R),l(R,H),n(e,A,c),Pn[I].m(e,c),n(e,C,c),n(e,N,c),l(N,K),n(e,X,c),n(e,z,c),l(z,W),l(W,G),l(G,Q),l(W,Y),l(z,V),l(z,te),l(te,B),l(B,ee),l(te,U),l(z,Z),l(z,L),l(L,se),l(se,J),l(L,pe),n(e,fe,c),x(ie,e,c),n(e,Se,c),n(e,re,c),l(re,Ns),n(e,js,c),n(e,ue,c),n(e,Ls,c),n(e,ae,c),n(e,ke,c),n(e,je,c),l(je,_e),l(je,rl),l(je,de),n(e,gs,c),n(e,ge,c),l(ge,Pl),l(ge,Te),l(Te,vs),l(ge,nl),n(e,Ne,c),n(e,ws,c),l(ws,ol),n(e,ve,c),n(e,Le,c),l(Le,ce),l(Le,Es),l(Es,xs),l(Le,lt),n(e,zl,c),x(De,e,c),n(e,cs,c),n(e,Fe,c),l(Fe,le),l(le,pl),x(es,pl,null),l(Fe,Al),l(Fe,ss),l(ss,ls),n(e,he,c),n(e,fs,c),l(fs,il),l(fs,cl),l(cl,fl),l(fs,ml),n(e,Il,c),x(ts,e,c),n(e,ul,c),n(e,be,c),l(be,_l),l(be,ms),l(ms,tt),l(be,Rl),n(e,as,c),x(we,e,c),n(e,Me,c),x(ne,e,c),n(e,Fs,c),n(e,He,c),l(He,at),l(He,Ms),l(Ms,Ee),l(He,Hs),n(e,ys,c),n(e,Gs,c),l(Gs,Sl),n(e,Pe,c),x(Os,e,c),n(e,Us,c),x(rs,e,c),n(e,Bl,c),n(e,Cs,c),l(Cs,ns),n(e,dl,c),x(Ge,e,c),n(e,hl,c),x(xe,e,c),n(e,os,c),n(e,Ue,c),l(Ue,us),n(e,bl,c),x(ye,e,c),n(e,Nl,c),x(_s,e,c),n(e,_,c),n(e,D,c),l(D,Ws),l(D,$l),l($l,Xs),l(D,Zs),l(D,kl),l(kl,qs),l(D,Ll),l(D,Ts),l(Ts,Ks),l(D,Mt),l(D,jl),l(jl,Vs),l(D,Ht),n(e,Fl,c),x(We,e,c),n(e,Xe,c),x(ps,e,c),n(e,rt,c),n(e,Ze,c),l(Ze,Ke),l(Ze,Ys),l(Ys,is),l(Ze,Ml),l(Ze,Js),l(Js,Oe),l(Ze,Gt),n(e,Qs,c),n(e,$e,c),l($e,gl),l(gl,vl),l(vl,el),l(gl,nt),l($e,Ds),l($e,Hl),l(Hl,ot),l(ot,Pr),l(Hl,zr),l(Hl,Ut),l(Ut,pt),l(Hl,tr),l($e,it),l($e,wl),l(wl,ds),l(ds,Ar),l(wl,_a),l(wl,da),l(da,Ir),l(wl,ha),l($e,Rr),l($e,Gl),l(Gl,Wt),l(Wt,ct),l(Gl,ar),l(Gl,Ve),l(Ve,Sr),l(Gl,ba),l($e,Br),l($e,Ul),l(Ul,ft),l(ft,Nr),l(Ul,Lr),l(Ul,mt),l(mt,Fr),l(Ul,Mr),n(e,$a,c),n(e,sl,c),l(sl,rr),n(e,Wl,c),x(Xl,e,c),n(e,ut,c),x(_t,e,c),n(e,ka,c),n(e,Ye,c),l(Ye,nr),l(Ye,hs),l(hs,Hr),l(Ye,ja),l(Ye,ga),l(ga,Gr),l(Ye,va),n(e,or,c),x(dt,e,c),n(e,wa,c),n(e,bs,c),l(bs,Zl),n(e,Xt,c),x($s,e,c),n(e,pr,c),n(e,El,c),l(El,Ur),n(e,Ea,c),x(Ps,e,c),n(e,ir,c),n(e,xl,c),l(xl,ht),l(xl,bt),l(bt,Zt),l(xl,Wr),n(e,xa,c),n(e,ze,c),l(ze,$t),l(ze,ya),l(ya,Oa),l(ze,Xr),n(e,cr,c),x(kt,e,c),n(e,Je,c),n(e,Ce,c),l(Ce,Ca),l(Ce,qa),l(qa,Zr),l(Ce,Ta),l(Ce,jt),l(jt,Kr),l(Ce,Da),l(Ce,gt),l(gt,Vr),l(Ce,Pa),l(Ce,za),l(za,Yr),l(Ce,Jr),l(Ce,zs),l(zs,Qr),l(Ce,Aa),n(e,fr,c),x(vt,e,c),n(e,Kt,c),x(wt,e,c),n(e,mr,c),n(e,As,c),l(As,Vt),l(As,Ia),l(Ia,ur),l(As,Et),l(As,Yt),l(Yt,Jt),l(As,en),n(e,Ra,c),x(Is,e,c),n(e,Sa,c),x(oe,e,c),n(e,_r,c),n(e,me,c),l(me,sn),l(me,Ba),l(Ba,Na),l(me,ln),l(me,La),l(La,Fa),l(me,tn),l(me,Ma),l(Ma,Ha),l(me,an),l(me,Ga),l(Ga,Ua),l(me,rn),l(me,Wa),l(Wa,Xa),l(me,nn),l(me,Qt),l(Qt,Za),l(me,on),n(e,dr,c),x(Kl,e,c),n(e,Rs,c),x(xt,e,c),n(e,ea,c),n(e,Qe,c),l(Qe,pn),l(Qe,yl),l(yl,cn),l(Qe,fn),l(Qe,sa),l(sa,r),l(Qe,h),l(Qe,Vl),l(Vl,Fn),l(Qe,Mn),l(Qe,Yl),l(Yl,Hn),l(Qe,Gn),n(e,Ka,c),x(la,e,c),n(e,yt,c),n(e,Va,c),l(Va,Un),n(e,mn,c),x(Jl,e,c),n(e,un,c),x(ta,e,c),n(e,Ya,c),n(e,Ol,c),l(Ol,ks),l(Ol,hr),l(hr,_n),l(Ol,Wn),l(Ol,br),l(br,Xn),l(Ol,Zn),n(e,Ja,c),x(Ot,e,c),n(e,dn,c),n(e,Ae,c),l(Ae,Kn),l(Ae,$r),l($r,kr),l(Ae,Vn),l(Ae,jr),l(jr,Yn),l(Ae,gr),l(Ae,vr),l(vr,Jn),l(Ae,Qn),l(Ae,Ql),l(Ql,eo),l(Ae,so),n(e,Qa,c),x(aa,e,c),n(e,Ct,c),n(e,er,c),l(er,lo),n(e,Cl,c),n(e,sr,c),l(sr,to),n(e,hn,c),x(ra,e,c),n(e,qt,c),n(e,Tt,c),l(Tt,ao),l(Tt,Dt),l(Dt,ro),l(Tt,no),n(e,bn,c),zn[ll].m(e,c),n(e,ql,c),n(e,et,c),l(et,oo),n(e,Ss,c),n(e,Bs,c),l(Bs,po),l(Bs,lr),l(lr,io),l(Bs,na),l(Bs,wr),l(wr,co),l(Bs,fo),l(Bs,Er),l(Er,qe),l(Bs,mo),n(e,$n,c),n(e,Tl,c),l(Tl,uo),l(Tl,oa),l(oa,xr),l(xr,_o),l(Tl,pa),l(Tl,yr),l(yr,ho),l(Tl,xp),n(e,Wo,c),An[Pt].m(e,c),n(e,bo,c),n(e,$o,c),l($o,yp),n(e,Xo,c),x(kn,e,c),n(e,Zo,c),x(jn,e,c),n(e,Ko,c),n(e,ko,c),l(ko,Op),n(e,Vo,c),x(gn,e,c),n(e,Yo,c),x(vn,e,c),n(e,Jo,c),In[At].m(e,c),n(e,jo,c),Ie&&Ie.m(e,c),n(e,go,c),n(e,wn,c),l(wn,Cp),n(e,Qo,c),Rn[Rt].m(e,c),n(e,vo,c),x(En,e,c),n(e,ep,c),n(e,wo,c),l(wo,qp),n(e,sp,c),x(xn,e,c),n(e,lp,c),x(yn,e,c),n(e,tp,c),n(e,Eo,c),l(Eo,Tp),n(e,ap,c),x(On,e,c),n(e,rp,c),n(e,xo,c),l(xo,Dp),n(e,np,c),x(Cn,e,c),n(e,op,c),Sn[Bt].m(e,c),n(e,yo,c),Re&&Re.m(e,c),n(e,Oo,c),n(e,qn,c),l(qn,Pp),n(e,pp,c),n(e,Or,c),l(Or,zp),l(Or,So),l(So,Ap),l(Or,Ip),n(e,ip,c),x(Tn,e,c),n(e,cp,c),x(Dn,e,c),n(e,fp,c),n(e,Co,c),l(Co,Rp),mp=!0},p(e,[c]){const Bn={};c&1&&(Bn.fw=e[0]),d.$set(Bn);let qo=I;I=Lp(e),I!==qo&&(Tr(),g(Pn[qo],1,1,()=>{Pn[qo]=null}),qr(),M=Pn[I],M||(M=Pn[I]=Np[I](e),M.c()),k(M,1),M.m(C.parentNode,C));const Bo={};c&2&&(Bo.$$scope={dirty:c,ctx:e}),De.$set(Bo);const No={};c&2&&(No.$$scope={dirty:c,ctx:e}),$s.$set(No);const Lo={};c&2&&(Lo.$$scope={dirty:c,ctx:e}),Ot.$set(Lo);let ia=ll;ll=Mp(e),ll!==ia&&(Tr(),g(zn[ia],1,1,()=>{zn[ia]=null}),qr(),tl=zn[ll],tl||(tl=zn[ll]=Fp[ll](e),tl.c()),k(tl,1),tl.m(ql.parentNode,ql));let Nn=Pt;Pt=Gp(e),Pt!==Nn&&(Tr(),g(An[Nn],1,1,()=>{An[Nn]=null}),qr(),zt=An[Pt],zt||(zt=An[Pt]=Hp[Pt](e),zt.c()),k(zt,1),zt.m(bo.parentNode,bo));let To=At;At=Wp(e),At!==To&&(Tr(),g(In[To],1,1,()=>{In[To]=null}),qr(),It=In[At],It||(It=In[At]=Up[At](e),It.c()),k(It,1),It.m(jo.parentNode,jo)),e[0]==="tf"?Ie?c&1&&k(Ie,1):(Ie=Ec(e),Ie.c(),k(Ie,1),Ie.m(go.parentNode,go)):Ie&&(Tr(),g(Ie,1,1,()=>{Ie=null}),qr());let Ln=Rt;Rt=Zp(e),Rt!==Ln&&(Tr(),g(Rn[Ln],1,1,()=>{Rn[Ln]=null}),qr(),St=Rn[Rt],St||(St=Rn[Rt]=Xp[Rt](e),St.c()),k(St,1),St.m(vo.parentNode,vo));let Do=Bt;Bt=Vp(e),Bt!==Do&&(Tr(),g(Sn[Do],1,1,()=>{Sn[Do]=null}),qr(),Nt=Sn[Bt],Nt||(Nt=Sn[Bt]=Kp[Bt](e),Nt.c()),k(Nt,1),Nt.m(yo.parentNode,yo)),e[0]==="pt"?Re?c&1&&k(Re,1):(Re=xc(e),Re.c(),k(Re,1),Re.m(Oo.parentNode,Oo)):Re&&(Tr(),g(Re,1,1,()=>{Re=null}),qr())},i(e){mp||(k(d.$$.fragment,e),k(T.$$.fragment,e),k(M),k(ie.$$.fragment,e),k(De.$$.fragment,e),k(es.$$.fragment,e),k(ts.$$.fragment,e),k(we.$$.fragment,e),k(ne.$$.fragment,e),k(Os.$$.fragment,e),k(rs.$$.fragment,e),k(Ge.$$.fragment,e),k(xe.$$.fragment,e),k(ye.$$.fragment,e),k(_s.$$.fragment,e),k(We.$$.fragment,e),k(ps.$$.fragment,e),k(Xl.$$.fragment,e),k(_t.$$.fragment,e),k(dt.$$.fragment,e),k($s.$$.fragment,e),k(Ps.$$.fragment,e),k(kt.$$.fragment,e),k(vt.$$.fragment,e),k(wt.$$.fragment,e),k(Is.$$.fragment,e),k(oe.$$.fragment,e),k(Kl.$$.fragment,e),k(xt.$$.fragment,e),k(la.$$.fragment,e),k(Jl.$$.fragment,e),k(ta.$$.fragment,e),k(Ot.$$.fragment,e),k(aa.$$.fragment,e),k(ra.$$.fragment,e),k(tl),k(zt),k(kn.$$.fragment,e),k(jn.$$.fragment,e),k(gn.$$.fragment,e),k(vn.$$.fragment,e),k(It),k(Ie),k(St),k(En.$$.fragment,e),k(xn.$$.fragment,e),k(yn.$$.fragment,e),k(On.$$.fragment,e),k(Cn.$$.fragment,e),k(Nt),k(Re),k(Tn.$$.fragment,e),k(Dn.$$.fragment,e),mp=!0)},o(e){g(d.$$.fragment,e),g(T.$$.fragment,e),g(M),g(ie.$$.fragment,e),g(De.$$.fragment,e),g(es.$$.fragment,e),g(ts.$$.fragment,e),g(we.$$.fragment,e),g(ne.$$.fragment,e),g(Os.$$.fragment,e),g(rs.$$.fragment,e),g(Ge.$$.fragment,e),g(xe.$$.fragment,e),g(ye.$$.fragment,e),g(_s.$$.fragment,e),g(We.$$.fragment,e),g(ps.$$.fragment,e),g(Xl.$$.fragment,e),g(_t.$$.fragment,e),g(dt.$$.fragment,e),g($s.$$.fragment,e),g(Ps.$$.fragment,e),g(kt.$$.fragment,e),g(vt.$$.fragment,e),g(wt.$$.fragment,e),g(Is.$$.fragment,e),g(oe.$$.fragment,e),g(Kl.$$.fragment,e),g(xt.$$.fragment,e),g(la.$$.fragment,e),g(Jl.$$.fragment,e),g(ta.$$.fragment,e),g(Ot.$$.fragment,e),g(aa.$$.fragment,e),g(ra.$$.fragment,e),g(tl),g(zt),g(kn.$$.fragment,e),g(jn.$$.fragment,e),g(gn.$$.fragment,e),g(vn.$$.fragment,e),g(It),g(Ie),g(St),g(En.$$.fragment,e),g(xn.$$.fragment,e),g(yn.$$.fragment,e),g(On.$$.fragment,e),g(Cn.$$.fragment,e),g(Nt),g(Re),g(Tn.$$.fragment,e),g(Dn.$$.fragment,e),mp=!1},d(e){s(u),e&&s(j),y(d,e),e&&s($),e&&s(q),y(T),e&&s(A),Pn[I].d(e),e&&s(C),e&&s(N),e&&s(X),e&&s(z),e&&s(fe),y(ie,e),e&&s(Se),e&&s(re),e&&s(js),e&&s(ue),e&&s(Ls),e&&s(ae),e&&s(ke),e&&s(je),e&&s(gs),e&&s(ge),e&&s(Ne),e&&s(ws),e&&s(ve),e&&s(Le),e&&s(zl),y(De,e),e&&s(cs),e&&s(Fe),y(es),e&&s(he),e&&s(fs),e&&s(Il),y(ts,e),e&&s(ul),e&&s(be),e&&s(as),y(we,e),e&&s(Me),y(ne,e),e&&s(Fs),e&&s(He),e&&s(ys),e&&s(Gs),e&&s(Pe),y(Os,e),e&&s(Us),y(rs,e),e&&s(Bl),e&&s(Cs),e&&s(dl),y(Ge,e),e&&s(hl),y(xe,e),e&&s(os),e&&s(Ue),e&&s(bl),y(ye,e),e&&s(Nl),y(_s,e),e&&s(_),e&&s(D),e&&s(Fl),y(We,e),e&&s(Xe),y(ps,e),e&&s(rt),e&&s(Ze),e&&s(Qs),e&&s($e),e&&s($a),e&&s(sl),e&&s(Wl),y(Xl,e),e&&s(ut),y(_t,e),e&&s(ka),e&&s(Ye),e&&s(or),y(dt,e),e&&s(wa),e&&s(bs),e&&s(Xt),y($s,e),e&&s(pr),e&&s(El),e&&s(Ea),y(Ps,e),e&&s(ir),e&&s(xl),e&&s(xa),e&&s(ze),e&&s(cr),y(kt,e),e&&s(Je),e&&s(Ce),e&&s(fr),y(vt,e),e&&s(Kt),y(wt,e),e&&s(mr),e&&s(As),e&&s(Ra),y(Is,e),e&&s(Sa),y(oe,e),e&&s(_r),e&&s(me),e&&s(dr),y(Kl,e),e&&s(Rs),y(xt,e),e&&s(ea),e&&s(Qe),e&&s(Ka),y(la,e),e&&s(yt),e&&s(Va),e&&s(mn),y(Jl,e),e&&s(un),y(ta,e),e&&s(Ya),e&&s(Ol),e&&s(Ja),y(Ot,e),e&&s(dn),e&&s(Ae),e&&s(Qa),y(aa,e),e&&s(Ct),e&&s(er),e&&s(Cl),e&&s(sr),e&&s(hn),y(ra,e),e&&s(qt),e&&s(Tt),e&&s(bn),zn[ll].d(e),e&&s(ql),e&&s(et),e&&s(Ss),e&&s(Bs),e&&s($n),e&&s(Tl),e&&s(Wo),An[Pt].d(e),e&&s(bo),e&&s($o),e&&s(Xo),y(kn,e),e&&s(Zo),y(jn,e),e&&s(Ko),e&&s(ko),e&&s(Vo),y(gn,e),e&&s(Yo),y(vn,e),e&&s(Jo),In[At].d(e),e&&s(jo),Ie&&Ie.d(e),e&&s(go),e&&s(wn),e&&s(Qo),Rn[Rt].d(e),e&&s(vo),y(En,e),e&&s(ep),e&&s(wo),e&&s(sp),y(xn,e),e&&s(lp),y(yn,e),e&&s(tp),e&&s(Eo),e&&s(ap),y(On,e),e&&s(rp),e&&s(xo),e&&s(np),y(Cn,e),e&&s(op),Sn[Bt].d(e),e&&s(yo),Re&&Re.d(e),e&&s(Oo),e&&s(qn),e&&s(pp),e&&s(Or),e&&s(ip),y(Tn,e),e&&s(cp),y(Dn,e),e&&s(fp),e&&s(Co)}}}const ef={local:"token",sections:[{local:"",sections:[{local:"conll2003",title:"CoNLL-2003 \u6570\u636E\u96C6"},{local:"",title:"\u5904\u7406\u6570\u636E"}],title:"\u51C6\u5907\u6570\u636E"},{local:"trainer-api",title:"\u4F7F\u7528 Trainer API \u5FAE\u8C03\u6A21\u578B"},{local:"keras",sections:[{local:"",title:"\u6570\u636E\u6392\u5E8F"},{local:"",title:"\u5B9A\u4E49\u6A21\u578B"},{local:"",title:"\u5FAE\u8C03\u6A21\u578B"},{local:"",title:"\u8BC4\u4F30\u6307\u6807"},{local:"",title:"\u5B9A\u4E49\u6A21\u578B"},{local:"",title:"\u5FAE\u8C03\u6A21\u578B"}],title:"\u4F7F\u7528 Keras \u5FAE\u8C03\u6A21\u578B"},{local:"",sections:[{local:"",title:"\u505A\u597D\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"},{local:"training-loop",title:"Training loop"},{local:"",title:"\u8BAD\u7EC3\u5FAA\u73AF"}],title:"\u81EA\u5B9A\u4E49\u8BAD\u7EC3\u5FAA\u73AF"},{local:"",title:"\u4F7F\u7528\u5FAE\u8C03\u6A21\u578B"}],title:"Token \u5206\u7C7B"};function sf(F,u,j){let d="pt";return Dc(()=>{const $=new URLSearchParams(window.location.search);j(0,d=$.get("fw")||"pt")}),[d]}class cf extends Oc{constructor(u){super();Cc(this,u,sf,Qc,qc,{})}}export{cf as default,ef as metadata};
