import{S as mr,i as dr,s as $r,e as n,k as $,w as B,t as a,M as _r,c as l,d as r,m as _,a as i,x as V,h as s,b as m,G as t,g as f,y as U,q as W,o as J,B as K,v as vr,L as kr}from"../chunks/vendor-hf-doc-builder.js";import{T as ur}from"../chunks/Tip-hf-doc-builder.js";import{I as Ue}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as be}from"../chunks/CodeBlock-hf-doc-builder.js";import{F as wr,M as hr}from"../chunks/Markdown-hf-doc-builder.js";function br(oe){let o,y,p,w,E,g,D,L;return{c(){o=n("p"),y=a("Remember, architecture refers to the skeleton of the model and checkpoints are the weights for a given architecture. For example, "),p=n("a"),w=a("BERT"),E=a(" is an architecture, while "),g=n("code"),D=a("bert-base-uncased"),L=a(" is a checkpoint. Model is a general term that can mean either architecture or checkpoint."),this.h()},l(A){o=l(A,"P",{});var x=i(o);y=s(x,"Remember, architecture refers to the skeleton of the model and checkpoints are the weights for a given architecture. For example, "),p=l(x,"A",{href:!0,rel:!0});var T=i(p);w=s(T,"BERT"),T.forEach(r),E=s(x," is an architecture, while "),g=l(x,"CODE",{});var C=i(g);D=s(C,"bert-base-uncased"),C.forEach(r),L=s(x," is a checkpoint. Model is a general term that can mean either architecture or checkpoint."),x.forEach(r),this.h()},h(){m(p,"href","https://huggingface.co/bert-base-uncased"),m(p,"rel","nofollow")},m(A,x){f(A,o,x),t(o,y),t(o,p),t(p,w),t(o,E),t(o,g),t(g,D),t(o,L)},d(A){A&&r(o)}}}function gr(oe){let o,y,p,w,E,g,D,L,A,x,T,C,P,Q,q,X,Y,j,H,b,G,v,ae,S,F,Z,N,R,ee,I,re,h;return{c(){o=n("p"),y=a("For PyTorch models, the "),p=n("code"),w=a("from_pretrained()"),E=a(" method uses "),g=n("code"),D=a("torch.load()"),L=a(" which internally uses "),A=n("code"),x=a("pickle"),T=a(" and is known to be insecure. In general, never load a model that could have come from an untrusted source, or that could have been tampered with. This security risk is partially mitigated for public models hosted on the Hugging Face Hub, which are "),C=n("a"),P=a("scanned for malware"),Q=a(" at each commit. See the "),q=n("a"),X=a("Hub documentation"),Y=a(" for best practices like "),j=n("a"),H=a("signed commit verification"),b=a(" with GPG."),G=$(),v=n("p"),ae=a("TensorFlow and Flax checkpoints are not affected, and can be loaded within PyTorch architectures using the "),S=n("code"),F=a("from_tf"),Z=a(" and "),N=n("code"),R=a("from_flax"),ee=a(" kwargs for the "),I=n("code"),re=a("from_pretrained"),h=a(" method to circumvent this issue."),this.h()},l(d){o=l(d,"P",{});var c=i(o);y=s(c,"For PyTorch models, the "),p=l(c,"CODE",{});var k=i(p);w=s(k,"from_pretrained()"),k.forEach(r),E=s(c," method uses "),g=l(c,"CODE",{});var se=i(g);D=s(se,"torch.load()"),se.forEach(r),L=s(c," which internally uses "),A=l(c,"CODE",{});var ne=i(A);x=s(ne,"pickle"),ne.forEach(r),T=s(c," and is known to be insecure. In general, never load a model that could have come from an untrusted source, or that could have been tampered with. This security risk is partially mitigated for public models hosted on the Hugging Face Hub, which are "),C=l(c,"A",{href:!0,rel:!0});var M=i(C);P=s(M,"scanned for malware"),M.forEach(r),Q=s(c," at each commit. See the "),q=l(c,"A",{href:!0,rel:!0});var te=i(q);X=s(te,"Hub documentation"),te.forEach(r),Y=s(c," for best practices like "),j=l(c,"A",{href:!0,rel:!0});var O=i(j);H=s(O,"signed commit verification"),O.forEach(r),b=s(c," with GPG."),c.forEach(r),G=_(d),v=l(d,"P",{});var z=i(v);ae=s(z,"TensorFlow and Flax checkpoints are not affected, and can be loaded within PyTorch architectures using the "),S=l(z,"CODE",{});var ie=i(S);F=s(ie,"from_tf"),ie.forEach(r),Z=s(z," and "),N=l(z,"CODE",{});var le=i(N);R=s(le,"from_flax"),le.forEach(r),ee=s(z," kwargs for the "),I=l(z,"CODE",{});var Pe=i(I);re=s(Pe,"from_pretrained"),Pe.forEach(r),h=s(z," method to circumvent this issue."),z.forEach(r),this.h()},h(){m(C,"href","https://huggingface.co/docs/hub/security-malware"),m(C,"rel","nofollow"),m(q,"href","https://huggingface.co/docs/hub/security"),m(q,"rel","nofollow"),m(j,"href","https://huggingface.co/docs/hub/security-gpg#signing-commits-with-gpg"),m(j,"rel","nofollow")},m(d,c){f(d,o,c),t(o,y),t(o,p),t(p,w),t(o,E),t(o,g),t(g,D),t(o,L),t(o,A),t(A,x),t(o,T),t(o,C),t(C,P),t(o,Q),t(o,q),t(q,X),t(o,Y),t(o,j),t(j,H),t(o,b),f(d,G,c),f(d,v,c),t(v,ae),t(v,S),t(S,F),t(v,Z),t(v,N),t(N,R),t(v,ee),t(v,I),t(I,re),t(v,h)},d(d){d&&r(o),d&&r(G),d&&r(v)}}}function yr(oe){let o,y,p,w,E,g,D,L,A,x,T,C,P,Q,q,X,Y,j,H,b,G,v,ae,S,F,Z,N,R,ee,I,re,h,d;return P=new be({props:{code:`from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),j=new be({props:{code:`from transformers import AutoModelForTokenClassification

model = AutoModelForTokenClassification.from_pretrained("distilbert-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForTokenClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForTokenClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),b=new ur({props:{warning:!0,$$slots:{default:[gr]},$$scope:{ctx:oe}}}),{c(){o=n("p"),y=a("Finally, the "),p=n("code"),w=a("AutoModelFor"),E=a(" classes let you load a pretrained model for a given task (see "),g=n("a"),D=a("here"),L=a(" for a complete list of available tasks). For example, load a model for sequence classification with "),A=n("a"),x=a("AutoModelForSequenceClassification.from_pretrained()"),T=a(":"),C=$(),B(P.$$.fragment),Q=$(),q=n("p"),X=a("Easily reuse the same checkpoint to load an architecture for a different task:"),Y=$(),B(j.$$.fragment),H=$(),B(b.$$.fragment),G=$(),v=n("p"),ae=a("Generally, we recommend using the "),S=n("code"),F=a("AutoTokenizer"),Z=a(" class and the "),N=n("code"),R=a("AutoModelFor"),ee=a(" class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),I=n("a"),re=a("tutorial"),h=a(", learn how to use your newly loaded tokenizer, feature extractor and processor to preprocess a dataset for fine-tuning."),this.h()},l(c){o=l(c,"P",{});var k=i(o);y=s(k,"Finally, the "),p=l(k,"CODE",{});var se=i(p);w=s(se,"AutoModelFor"),se.forEach(r),E=s(k," classes let you load a pretrained model for a given task (see "),g=l(k,"A",{href:!0});var ne=i(g);D=s(ne,"here"),ne.forEach(r),L=s(k," for a complete list of available tasks). For example, load a model for sequence classification with "),A=l(k,"A",{href:!0});var M=i(A);x=s(M,"AutoModelForSequenceClassification.from_pretrained()"),M.forEach(r),T=s(k,":"),k.forEach(r),C=_(c),V(P.$$.fragment,c),Q=_(c),q=l(c,"P",{});var te=i(q);X=s(te,"Easily reuse the same checkpoint to load an architecture for a different task:"),te.forEach(r),Y=_(c),V(j.$$.fragment,c),H=_(c),V(b.$$.fragment,c),G=_(c),v=l(c,"P",{});var O=i(v);ae=s(O,"Generally, we recommend using the "),S=l(O,"CODE",{});var z=i(S);F=s(z,"AutoTokenizer"),z.forEach(r),Z=s(O," class and the "),N=l(O,"CODE",{});var ie=i(N);R=s(ie,"AutoModelFor"),ie.forEach(r),ee=s(O," class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),I=l(O,"A",{href:!0});var le=i(I);re=s(le,"tutorial"),le.forEach(r),h=s(O,", learn how to use your newly loaded tokenizer, feature extractor and processor to preprocess a dataset for fine-tuning."),O.forEach(r),this.h()},h(){m(g,"href","model_doc/auto"),m(A,"href","/docs/transformers/pr_19907/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),m(I,"href","preprocessing")},m(c,k){f(c,o,k),t(o,y),t(o,p),t(p,w),t(o,E),t(o,g),t(g,D),t(o,L),t(o,A),t(A,x),t(o,T),f(c,C,k),U(P,c,k),f(c,Q,k),f(c,q,k),t(q,X),f(c,Y,k),U(j,c,k),f(c,H,k),U(b,c,k),f(c,G,k),f(c,v,k),t(v,ae),t(v,S),t(S,F),t(v,Z),t(v,N),t(N,R),t(v,ee),t(v,I),t(I,re),t(v,h),d=!0},p(c,k){const se={};k&2&&(se.$$scope={dirty:k,ctx:c}),b.$set(se)},i(c){d||(W(P.$$.fragment,c),W(j.$$.fragment,c),W(b.$$.fragment,c),d=!0)},o(c){J(P.$$.fragment,c),J(j.$$.fragment,c),J(b.$$.fragment,c),d=!1},d(c){c&&r(o),c&&r(C),K(P,c),c&&r(Q),c&&r(q),c&&r(Y),K(j,c),c&&r(H),K(b,c),c&&r(G),c&&r(v)}}}function Ar(oe){let o,y;return o=new hr({props:{$$slots:{default:[yr]},$$scope:{ctx:oe}}}),{c(){B(o.$$.fragment)},l(p){V(o.$$.fragment,p)},m(p,w){U(o,p,w),y=!0},p(p,w){const E={};w&2&&(E.$$scope={dirty:w,ctx:p}),o.$set(E)},i(p){y||(W(o.$$.fragment,p),y=!0)},o(p){J(o.$$.fragment,p),y=!1},d(p){K(o,p)}}}function Er(oe){let o,y,p,w,E,g,D,L,A,x,T,C,P,Q,q,X,Y,j,H,b,G,v,ae,S,F,Z,N,R,ee,I,re;return P=new be({props:{code:`from transformers import TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),j=new be({props:{code:`from transformers import TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained("distilbert-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForTokenClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForTokenClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),{c(){o=n("p"),y=a("Finally, the "),p=n("code"),w=a("TFAutoModelFor"),E=a(" classes let you load a pretrained model for a given task (see "),g=n("a"),D=a("here"),L=a(" for a complete list of available tasks). For example, load a model for sequence classification with "),A=n("a"),x=a("TFAutoModelForSequenceClassification.from_pretrained()"),T=a(":"),C=$(),B(P.$$.fragment),Q=$(),q=n("p"),X=a("Easily reuse the same checkpoint to load an architecture for a different task:"),Y=$(),B(j.$$.fragment),H=$(),b=n("p"),G=a("Generally, we recommend using the "),v=n("code"),ae=a("AutoTokenizer"),S=a(" class and the "),F=n("code"),Z=a("TFAutoModelFor"),N=a(" class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),R=n("a"),ee=a("tutorial"),I=a(", learn how to use your newly loaded tokenizer, feature extractor and processor to preprocess a dataset for fine-tuning."),this.h()},l(h){o=l(h,"P",{});var d=i(o);y=s(d,"Finally, the "),p=l(d,"CODE",{});var c=i(p);w=s(c,"TFAutoModelFor"),c.forEach(r),E=s(d," classes let you load a pretrained model for a given task (see "),g=l(d,"A",{href:!0});var k=i(g);D=s(k,"here"),k.forEach(r),L=s(d," for a complete list of available tasks). For example, load a model for sequence classification with "),A=l(d,"A",{href:!0});var se=i(A);x=s(se,"TFAutoModelForSequenceClassification.from_pretrained()"),se.forEach(r),T=s(d,":"),d.forEach(r),C=_(h),V(P.$$.fragment,h),Q=_(h),q=l(h,"P",{});var ne=i(q);X=s(ne,"Easily reuse the same checkpoint to load an architecture for a different task:"),ne.forEach(r),Y=_(h),V(j.$$.fragment,h),H=_(h),b=l(h,"P",{});var M=i(b);G=s(M,"Generally, we recommend using the "),v=l(M,"CODE",{});var te=i(v);ae=s(te,"AutoTokenizer"),te.forEach(r),S=s(M," class and the "),F=l(M,"CODE",{});var O=i(F);Z=s(O,"TFAutoModelFor"),O.forEach(r),N=s(M," class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),R=l(M,"A",{href:!0});var z=i(R);ee=s(z,"tutorial"),z.forEach(r),I=s(M,", learn how to use your newly loaded tokenizer, feature extractor and processor to preprocess a dataset for fine-tuning."),M.forEach(r),this.h()},h(){m(g,"href","model_doc/auto"),m(A,"href","/docs/transformers/pr_19907/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),m(R,"href","preprocessing")},m(h,d){f(h,o,d),t(o,y),t(o,p),t(p,w),t(o,E),t(o,g),t(g,D),t(o,L),t(o,A),t(A,x),t(o,T),f(h,C,d),U(P,h,d),f(h,Q,d),f(h,q,d),t(q,X),f(h,Y,d),U(j,h,d),f(h,H,d),f(h,b,d),t(b,G),t(b,v),t(v,ae),t(b,S),t(b,F),t(F,Z),t(b,N),t(b,R),t(R,ee),t(b,I),re=!0},p:kr,i(h){re||(W(P.$$.fragment,h),W(j.$$.fragment,h),re=!0)},o(h){J(P.$$.fragment,h),J(j.$$.fragment,h),re=!1},d(h){h&&r(o),h&&r(C),K(P,h),h&&r(Q),h&&r(q),h&&r(Y),K(j,h),h&&r(H),h&&r(b)}}}function jr(oe){let o,y;return o=new hr({props:{$$slots:{default:[Er]},$$scope:{ctx:oe}}}),{c(){B(o.$$.fragment)},l(p){V(o.$$.fragment,p)},m(p,w){U(o,p,w),y=!0},p(p,w){const E={};w&2&&(E.$$scope={dirty:w,ctx:p}),o.$set(E)},i(p){y||(W(o.$$.fragment,p),y=!0)},o(p){J(o.$$.fragment,p),y=!1},d(p){K(o,p)}}}function Fr(oe){let o,y,p,w,E,g,D,L,A,x,T,C,P,Q,q,X,Y,j,H,b,G,v,ae,S,F,Z,N,R,ee,I,re,h,d,c,k,se,ne,M,te,O,z,ie,le,Pe,We,qe,_t,Je,ue,vt,Ce,kt,wt,Ke,ge,Qe,Me,bt,Xe,ye,Ye,ce,he,De,Ae,gt,Ne,yt,Ze,ze,At,et,me,Et,Le,jt,Ft,tt,Ee,rt,pe,de,He,je,xt,Ge,Tt,at,$e,Pt,Se,qt,Ct,st,_e,Mt,Ie,zt,Lt,ot,Fe,nt,fe,ve,Re,xe,St,Be,It,lt,ke,it;return g=new Ue({}),b=new ur({props:{$$slots:{default:[br]},$$scope:{ctx:oe}}}),z=new Ue({}),ge=new be({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;bert-base-uncased&quot;</span>)`}}),ye=new be({props:{code:`sequence = "In a hole in the ground there lived a hobbit."
print(tokenizer(sequence))`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>sequence = <span class="hljs-string">&quot;In a hole in the ground there lived a hobbit.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(tokenizer(sequence))
{<span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">101</span>, <span class="hljs-number">1999</span>, <span class="hljs-number">1037</span>, <span class="hljs-number">4920</span>, <span class="hljs-number">1999</span>, <span class="hljs-number">1996</span>, <span class="hljs-number">2598</span>, <span class="hljs-number">2045</span>, <span class="hljs-number">2973</span>, <span class="hljs-number">1037</span>, <span class="hljs-number">7570</span>, <span class="hljs-number">10322</span>, <span class="hljs-number">4183</span>, <span class="hljs-number">1012</span>, <span class="hljs-number">102</span>], 
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>], 
 <span class="hljs-string">&#x27;attention_mask&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]}`}}),Ae=new Ue({}),Ee=new be({props:{code:`from transformers import AutoFeatureExtractor

feature_extractor = AutoFeatureExtractor.from_pretrained(
    "ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoFeatureExtractor

<span class="hljs-meta">&gt;&gt;&gt; </span>feature_extractor = AutoFeatureExtractor.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition&quot;</span>
<span class="hljs-meta">... </span>)`}}),je=new Ue({}),Fe=new be({props:{code:`from transformers import AutoProcessor

processor = AutoProcessor.from_pretrained("microsoft/layoutlmv2-base-uncased")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;microsoft/layoutlmv2-base-uncased&quot;</span>)`}}),xe=new Ue({}),ke=new wr({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[jr],pytorch:[Ar]},$$scope:{ctx:oe}}}),{c(){o=n("meta"),y=$(),p=n("h1"),w=n("a"),E=n("span"),B(g.$$.fragment),D=$(),L=n("span"),A=a("Load pretrained instances with an AutoClass"),x=$(),T=n("p"),C=a("With so many different Transformer architectures, it can be challenging to create one for your checkpoint. As a part of \u{1F917} Transformers core philosophy to make the library easy, simple and flexible to use, an "),P=n("code"),Q=a("AutoClass"),q=a(" automatically infer and load the correct architecture from a given checkpoint. The "),X=n("code"),Y=a("from_pretrained()"),j=a(" method lets you quickly load a pretrained model for any architecture so you don\u2019t have to devote time and resources to train a model from scratch. Producing this type of checkpoint-agnostic code means if your code works for one checkpoint, it will work with another checkpoint - as long as it was trained for a similar task - even if the architecture is different."),H=$(),B(b.$$.fragment),G=$(),v=n("p"),ae=a("In this tutorial, learn to:"),S=$(),F=n("ul"),Z=n("li"),N=a("Load a pretrained tokenizer."),R=$(),ee=n("li"),I=a("Load a pretrained feature extractor."),re=$(),h=n("li"),d=a("Load a pretrained processor."),c=$(),k=n("li"),se=a("Load a pretrained model."),ne=$(),M=n("h2"),te=n("a"),O=n("span"),B(z.$$.fragment),ie=$(),le=n("span"),Pe=a("AutoTokenizer"),We=$(),qe=n("p"),_t=a("Nearly every NLP task begins with a tokenizer. A tokenizer converts your input into a format that can be processed by the model."),Je=$(),ue=n("p"),vt=a("Load a tokenizer with "),Ce=n("a"),kt=a("AutoTokenizer.from_pretrained()"),wt=a(":"),Ke=$(),B(ge.$$.fragment),Qe=$(),Me=n("p"),bt=a("Then tokenize your input as shown below:"),Xe=$(),B(ye.$$.fragment),Ye=$(),ce=n("h2"),he=n("a"),De=n("span"),B(Ae.$$.fragment),gt=$(),Ne=n("span"),yt=a("AutoFeatureExtractor"),Ze=$(),ze=n("p"),At=a("For audio and vision tasks, a feature extractor processes the audio signal or image into the correct input format."),et=$(),me=n("p"),Et=a("Load a feature extractor with "),Le=n("a"),jt=a("AutoFeatureExtractor.from_pretrained()"),Ft=a(":"),tt=$(),B(Ee.$$.fragment),rt=$(),pe=n("h2"),de=n("a"),He=n("span"),B(je.$$.fragment),xt=$(),Ge=n("span"),Tt=a("AutoProcessor"),at=$(),$e=n("p"),Pt=a("Multimodal tasks require a processor that combines two types of preprocessing tools. For example, the "),Se=n("a"),qt=a("LayoutLMV2"),Ct=a(" model requires a feature extractor to handle images and a tokenizer to handle text; a processor combines both of them."),st=$(),_e=n("p"),Mt=a("Load a processor with "),Ie=n("a"),zt=a("AutoProcessor.from_pretrained()"),Lt=a(":"),ot=$(),B(Fe.$$.fragment),nt=$(),fe=n("h2"),ve=n("a"),Re=n("span"),B(xe.$$.fragment),St=$(),Be=n("span"),It=a("AutoModel"),lt=$(),B(ke.$$.fragment),this.h()},l(e){const u=_r('[data-svelte="svelte-1phssyn"]',document.head);o=l(u,"META",{name:!0,content:!0}),u.forEach(r),y=_(e),p=l(e,"H1",{class:!0});var Te=i(p);w=l(Te,"A",{id:!0,class:!0,href:!0});var Ve=i(w);E=l(Ve,"SPAN",{});var Ot=i(E);V(g.$$.fragment,Ot),Ot.forEach(r),Ve.forEach(r),D=_(Te),L=l(Te,"SPAN",{});var Dt=i(L);A=s(Dt,"Load pretrained instances with an AutoClass"),Dt.forEach(r),Te.forEach(r),x=_(e),T=l(e,"P",{});var Oe=i(T);C=s(Oe,"With so many different Transformer architectures, it can be challenging to create one for your checkpoint. As a part of \u{1F917} Transformers core philosophy to make the library easy, simple and flexible to use, an "),P=l(Oe,"CODE",{});var Nt=i(P);Q=s(Nt,"AutoClass"),Nt.forEach(r),q=s(Oe," automatically infer and load the correct architecture from a given checkpoint. The "),X=l(Oe,"CODE",{});var Ht=i(X);Y=s(Ht,"from_pretrained()"),Ht.forEach(r),j=s(Oe," method lets you quickly load a pretrained model for any architecture so you don\u2019t have to devote time and resources to train a model from scratch. Producing this type of checkpoint-agnostic code means if your code works for one checkpoint, it will work with another checkpoint - as long as it was trained for a similar task - even if the architecture is different."),Oe.forEach(r),H=_(e),V(b.$$.fragment,e),G=_(e),v=l(e,"P",{});var Gt=i(v);ae=s(Gt,"In this tutorial, learn to:"),Gt.forEach(r),S=_(e),F=l(e,"UL",{});var we=i(F);Z=l(we,"LI",{});var Rt=i(Z);N=s(Rt,"Load a pretrained tokenizer."),Rt.forEach(r),R=_(we),ee=l(we,"LI",{});var Bt=i(ee);I=s(Bt,"Load a pretrained feature extractor."),Bt.forEach(r),re=_(we),h=l(we,"LI",{});var Vt=i(h);d=s(Vt,"Load a pretrained processor."),Vt.forEach(r),c=_(we),k=l(we,"LI",{});var Ut=i(k);se=s(Ut,"Load a pretrained model."),Ut.forEach(r),we.forEach(r),ne=_(e),M=l(e,"H2",{class:!0});var ct=i(M);te=l(ct,"A",{id:!0,class:!0,href:!0});var Wt=i(te);O=l(Wt,"SPAN",{});var Jt=i(O);V(z.$$.fragment,Jt),Jt.forEach(r),Wt.forEach(r),ie=_(ct),le=l(ct,"SPAN",{});var Kt=i(le);Pe=s(Kt,"AutoTokenizer"),Kt.forEach(r),ct.forEach(r),We=_(e),qe=l(e,"P",{});var Qt=i(qe);_t=s(Qt,"Nearly every NLP task begins with a tokenizer. A tokenizer converts your input into a format that can be processed by the model."),Qt.forEach(r),Je=_(e),ue=l(e,"P",{});var pt=i(ue);vt=s(pt,"Load a tokenizer with "),Ce=l(pt,"A",{href:!0});var Xt=i(Ce);kt=s(Xt,"AutoTokenizer.from_pretrained()"),Xt.forEach(r),wt=s(pt,":"),pt.forEach(r),Ke=_(e),V(ge.$$.fragment,e),Qe=_(e),Me=l(e,"P",{});var Yt=i(Me);bt=s(Yt,"Then tokenize your input as shown below:"),Yt.forEach(r),Xe=_(e),V(ye.$$.fragment,e),Ye=_(e),ce=l(e,"H2",{class:!0});var ft=i(ce);he=l(ft,"A",{id:!0,class:!0,href:!0});var Zt=i(he);De=l(Zt,"SPAN",{});var er=i(De);V(Ae.$$.fragment,er),er.forEach(r),Zt.forEach(r),gt=_(ft),Ne=l(ft,"SPAN",{});var tr=i(Ne);yt=s(tr,"AutoFeatureExtractor"),tr.forEach(r),ft.forEach(r),Ze=_(e),ze=l(e,"P",{});var rr=i(ze);At=s(rr,"For audio and vision tasks, a feature extractor processes the audio signal or image into the correct input format."),rr.forEach(r),et=_(e),me=l(e,"P",{});var ut=i(me);Et=s(ut,"Load a feature extractor with "),Le=l(ut,"A",{href:!0});var ar=i(Le);jt=s(ar,"AutoFeatureExtractor.from_pretrained()"),ar.forEach(r),Ft=s(ut,":"),ut.forEach(r),tt=_(e),V(Ee.$$.fragment,e),rt=_(e),pe=l(e,"H2",{class:!0});var ht=i(pe);de=l(ht,"A",{id:!0,class:!0,href:!0});var sr=i(de);He=l(sr,"SPAN",{});var or=i(He);V(je.$$.fragment,or),or.forEach(r),sr.forEach(r),xt=_(ht),Ge=l(ht,"SPAN",{});var nr=i(Ge);Tt=s(nr,"AutoProcessor"),nr.forEach(r),ht.forEach(r),at=_(e),$e=l(e,"P",{});var mt=i($e);Pt=s(mt,"Multimodal tasks require a processor that combines two types of preprocessing tools. For example, the "),Se=l(mt,"A",{href:!0});var lr=i(Se);qt=s(lr,"LayoutLMV2"),lr.forEach(r),Ct=s(mt," model requires a feature extractor to handle images and a tokenizer to handle text; a processor combines both of them."),mt.forEach(r),st=_(e),_e=l(e,"P",{});var dt=i(_e);Mt=s(dt,"Load a processor with "),Ie=l(dt,"A",{href:!0});var ir=i(Ie);zt=s(ir,"AutoProcessor.from_pretrained()"),ir.forEach(r),Lt=s(dt,":"),dt.forEach(r),ot=_(e),V(Fe.$$.fragment,e),nt=_(e),fe=l(e,"H2",{class:!0});var $t=i(fe);ve=l($t,"A",{id:!0,class:!0,href:!0});var cr=i(ve);Re=l(cr,"SPAN",{});var pr=i(Re);V(xe.$$.fragment,pr),pr.forEach(r),cr.forEach(r),St=_($t),Be=l($t,"SPAN",{});var fr=i(Be);It=s(fr,"AutoModel"),fr.forEach(r),$t.forEach(r),lt=_(e),V(ke.$$.fragment,e),this.h()},h(){m(o,"name","hf:doc:metadata"),m(o,"content",JSON.stringify(xr)),m(w,"id","load-pretrained-instances-with-an-autoclass"),m(w,"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"),m(w,"href","#load-pretrained-instances-with-an-autoclass"),m(p,"class","relative group"),m(te,"id","autotokenizer"),m(te,"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"),m(te,"href","#autotokenizer"),m(M,"class","relative group"),m(Ce,"href","/docs/transformers/pr_19907/en/model_doc/auto#transformers.AutoTokenizer.from_pretrained"),m(he,"id","autofeatureextractor"),m(he,"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"),m(he,"href","#autofeatureextractor"),m(ce,"class","relative group"),m(Le,"href","/docs/transformers/pr_19907/en/model_doc/auto#transformers.AutoFeatureExtractor.from_pretrained"),m(de,"id","autoprocessor"),m(de,"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"),m(de,"href","#autoprocessor"),m(pe,"class","relative group"),m(Se,"href","model_doc/layoutlmv2"),m(Ie,"href","/docs/transformers/pr_19907/en/model_doc/auto#transformers.AutoProcessor.from_pretrained"),m(ve,"id","automodel"),m(ve,"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"),m(ve,"href","#automodel"),m(fe,"class","relative group")},m(e,u){t(document.head,o),f(e,y,u),f(e,p,u),t(p,w),t(w,E),U(g,E,null),t(p,D),t(p,L),t(L,A),f(e,x,u),f(e,T,u),t(T,C),t(T,P),t(P,Q),t(T,q),t(T,X),t(X,Y),t(T,j),f(e,H,u),U(b,e,u),f(e,G,u),f(e,v,u),t(v,ae),f(e,S,u),f(e,F,u),t(F,Z),t(Z,N),t(F,R),t(F,ee),t(ee,I),t(F,re),t(F,h),t(h,d),t(F,c),t(F,k),t(k,se),f(e,ne,u),f(e,M,u),t(M,te),t(te,O),U(z,O,null),t(M,ie),t(M,le),t(le,Pe),f(e,We,u),f(e,qe,u),t(qe,_t),f(e,Je,u),f(e,ue,u),t(ue,vt),t(ue,Ce),t(Ce,kt),t(ue,wt),f(e,Ke,u),U(ge,e,u),f(e,Qe,u),f(e,Me,u),t(Me,bt),f(e,Xe,u),U(ye,e,u),f(e,Ye,u),f(e,ce,u),t(ce,he),t(he,De),U(Ae,De,null),t(ce,gt),t(ce,Ne),t(Ne,yt),f(e,Ze,u),f(e,ze,u),t(ze,At),f(e,et,u),f(e,me,u),t(me,Et),t(me,Le),t(Le,jt),t(me,Ft),f(e,tt,u),U(Ee,e,u),f(e,rt,u),f(e,pe,u),t(pe,de),t(de,He),U(je,He,null),t(pe,xt),t(pe,Ge),t(Ge,Tt),f(e,at,u),f(e,$e,u),t($e,Pt),t($e,Se),t(Se,qt),t($e,Ct),f(e,st,u),f(e,_e,u),t(_e,Mt),t(_e,Ie),t(Ie,zt),t(_e,Lt),f(e,ot,u),U(Fe,e,u),f(e,nt,u),f(e,fe,u),t(fe,ve),t(ve,Re),U(xe,Re,null),t(fe,St),t(fe,Be),t(Be,It),f(e,lt,u),U(ke,e,u),it=!0},p(e,[u]){const Te={};u&2&&(Te.$$scope={dirty:u,ctx:e}),b.$set(Te);const Ve={};u&2&&(Ve.$$scope={dirty:u,ctx:e}),ke.$set(Ve)},i(e){it||(W(g.$$.fragment,e),W(b.$$.fragment,e),W(z.$$.fragment,e),W(ge.$$.fragment,e),W(ye.$$.fragment,e),W(Ae.$$.fragment,e),W(Ee.$$.fragment,e),W(je.$$.fragment,e),W(Fe.$$.fragment,e),W(xe.$$.fragment,e),W(ke.$$.fragment,e),it=!0)},o(e){J(g.$$.fragment,e),J(b.$$.fragment,e),J(z.$$.fragment,e),J(ge.$$.fragment,e),J(ye.$$.fragment,e),J(Ae.$$.fragment,e),J(Ee.$$.fragment,e),J(je.$$.fragment,e),J(Fe.$$.fragment,e),J(xe.$$.fragment,e),J(ke.$$.fragment,e),it=!1},d(e){r(o),e&&r(y),e&&r(p),K(g),e&&r(x),e&&r(T),e&&r(H),K(b,e),e&&r(G),e&&r(v),e&&r(S),e&&r(F),e&&r(ne),e&&r(M),K(z),e&&r(We),e&&r(qe),e&&r(Je),e&&r(ue),e&&r(Ke),K(ge,e),e&&r(Qe),e&&r(Me),e&&r(Xe),K(ye,e),e&&r(Ye),e&&r(ce),K(Ae),e&&r(Ze),e&&r(ze),e&&r(et),e&&r(me),e&&r(tt),K(Ee,e),e&&r(rt),e&&r(pe),K(je),e&&r(at),e&&r($e),e&&r(st),e&&r(_e),e&&r(ot),K(Fe,e),e&&r(nt),e&&r(fe),K(xe),e&&r(lt),K(ke,e)}}}const xr={local:"load-pretrained-instances-with-an-autoclass",sections:[{local:"autotokenizer",title:"AutoTokenizer"},{local:"autofeatureextractor",title:"AutoFeatureExtractor"},{local:"autoprocessor",title:"AutoProcessor"},{local:"automodel",title:"AutoModel"}],title:"Load pretrained instances with an AutoClass"};function Tr(oe){return vr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Lr extends mr{constructor(o){super();dr(this,o,Tr,Fr,$r,{})}}export{Lr as default,xr as metadata};
