import{S as Sr,i as Ir,s as Nr,e as n,k as m,w as N,t as a,M as Or,c as l,d as r,m as d,a as i,x as O,h as s,b as $,G as t,g as p,y as D,q as H,o as G,B as R,v as Dr,L as Hr}from"../chunks/vendor-hf-doc-builder.js";import{T as zr}from"../chunks/Tip-hf-doc-builder.js";import{I as Be}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as de}from"../chunks/CodeBlock-hf-doc-builder.js";import{F as Gr,M as Lr}from"../chunks/Markdown-hf-doc-builder.js";function Rr(oe){let o,y,f,k,j,b,B,z;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, "),f=n("a"),k=a("BERT"),j=a(" is an architecture, while "),b=n("code"),B=a("bert-base-uncased"),z=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, "),f=l(x,"A",{href:!0,rel:!0});var P=i(f);k=s(P,"BERT"),P.forEach(r),j=s(x," is an architecture, while "),b=l(x,"CODE",{});var C=i(b);B=s(C,"bert-base-uncased"),C.forEach(r),z=s(x," is a checkpoint. Model is a general term that can mean either architecture or checkpoint."),x.forEach(r),this.h()},h(){$(f,"href","https://huggingface.co/bert-base-uncased"),$(f,"rel","nofollow")},m(A,x){p(A,o,x),t(o,y),t(o,f),t(f,k),t(o,j),t(o,b),t(b,B),t(o,z)},d(A){A&&r(o)}}}function Br(oe){let o,y,f,k,j,b,B,z,A,x,P,C,T,Q,q,X,Y,F,W,w,J,_,re,L,E,Z,V,K,ee,S,te,h;return{c(){o=n("p"),y=a("For PyTorch models, the "),f=n("code"),k=a("from_pretrained()"),j=a(" method uses "),b=n("code"),B=a("torch.load()"),z=a(" which internally uses "),A=n("code"),x=a("pickle"),P=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"),T=a("scanned for malware"),Q=a(" at each commit. See the "),q=n("a"),X=a("Hub documentation"),Y=a(" for best practices like "),F=n("a"),W=a("signed commit verification"),w=a(" with GPG."),J=m(),_=n("p"),re=a("TensorFlow and Flax checkpoints are not affected, and can be loaded within PyTorch architectures using the "),L=n("code"),E=a("from_tf"),Z=a(" and "),V=n("code"),K=a("from_flax"),ee=a(" kwargs for the "),S=n("code"),te=a("from_pretrained"),h=a(" method to circumvent this issue."),this.h()},l(v){o=l(v,"P",{});var c=i(o);y=s(c,"For PyTorch models, the "),f=l(c,"CODE",{});var g=i(f);k=s(g,"from_pretrained()"),g.forEach(r),j=s(c," method uses "),b=l(c,"CODE",{});var ae=i(b);B=s(ae,"torch.load()"),ae.forEach(r),z=s(c," which internally uses "),A=l(c,"CODE",{});var ne=i(A);x=s(ne,"pickle"),ne.forEach(r),P=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 I=i(C);T=s(I,"scanned for malware"),I.forEach(r),Q=s(c," at each commit. See the "),q=l(c,"A",{href:!0,rel:!0});var le=i(q);X=s(le,"Hub documentation"),le.forEach(r),Y=s(c," for best practices like "),F=l(c,"A",{href:!0,rel:!0});var U=i(F);W=s(U,"signed commit verification"),U.forEach(r),w=s(c," with GPG."),c.forEach(r),J=d(v),_=l(v,"P",{});var M=i(_);re=s(M,"TensorFlow and Flax checkpoints are not affected, and can be loaded within PyTorch architectures using the "),L=l(M,"CODE",{});var se=i(L);E=s(se,"from_tf"),se.forEach(r),Z=s(M," and "),V=l(M,"CODE",{});var ie=i(V);K=s(ie,"from_flax"),ie.forEach(r),ee=s(M," kwargs for the "),S=l(M,"CODE",{});var ce=i(S);te=s(ce,"from_pretrained"),ce.forEach(r),h=s(M," method to circumvent this issue."),M.forEach(r),this.h()},h(){$(C,"href","https://huggingface.co/docs/hub/security-malware"),$(C,"rel","nofollow"),$(q,"href","https://huggingface.co/docs/hub/security"),$(q,"rel","nofollow"),$(F,"href","https://huggingface.co/docs/hub/security-gpg#signing-commits-with-gpg"),$(F,"rel","nofollow")},m(v,c){p(v,o,c),t(o,y),t(o,f),t(f,k),t(o,j),t(o,b),t(b,B),t(o,z),t(o,A),t(A,x),t(o,P),t(o,C),t(C,T),t(o,Q),t(o,q),t(q,X),t(o,Y),t(o,F),t(F,W),t(o,w),p(v,J,c),p(v,_,c),t(_,re),t(_,L),t(L,E),t(_,Z),t(_,V),t(V,K),t(_,ee),t(_,S),t(S,te),t(_,h)},d(v){v&&r(o),v&&r(J),v&&r(_)}}}function Vr(oe){let o,y,f,k,j,b,B,z,A,x,P,C,T,Q,q,X,Y,F,W,w,J,_,re,L,E,Z,V,K,ee,S,te,h,v;return T=new de({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>)`}}),F=new de({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>)`}}),w=new zr({props:{warning:!0,$$slots:{default:[Br]},$$scope:{ctx:oe}}}),{c(){o=n("p"),y=a("Finally, the "),f=n("code"),k=a("AutoModelFor"),j=a(" classes let you load a pretrained model for a given task (see "),b=n("a"),B=a("here"),z=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()"),P=a(":"),C=m(),N(T.$$.fragment),Q=m(),q=n("p"),X=a("Easily reuse the same checkpoint to load an architecture for a different task:"),Y=m(),N(F.$$.fragment),W=m(),N(w.$$.fragment),J=m(),_=n("p"),re=a("Generally, we recommend using the "),L=n("code"),E=a("AutoTokenizer"),Z=a(" class and the "),V=n("code"),K=a("AutoModelFor"),ee=a(" class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),S=n("a"),te=a("tutorial"),h=a(", learn how to use your newly loaded tokenizer, image processor, feature extractor and processor to preprocess a dataset for fine-tuning."),this.h()},l(c){o=l(c,"P",{});var g=i(o);y=s(g,"Finally, the "),f=l(g,"CODE",{});var ae=i(f);k=s(ae,"AutoModelFor"),ae.forEach(r),j=s(g," classes let you load a pretrained model for a given task (see "),b=l(g,"A",{href:!0});var ne=i(b);B=s(ne,"here"),ne.forEach(r),z=s(g," for a complete list of available tasks). For example, load a model for sequence classification with "),A=l(g,"A",{href:!0});var I=i(A);x=s(I,"AutoModelForSequenceClassification.from_pretrained()"),I.forEach(r),P=s(g,":"),g.forEach(r),C=d(c),O(T.$$.fragment,c),Q=d(c),q=l(c,"P",{});var le=i(q);X=s(le,"Easily reuse the same checkpoint to load an architecture for a different task:"),le.forEach(r),Y=d(c),O(F.$$.fragment,c),W=d(c),O(w.$$.fragment,c),J=d(c),_=l(c,"P",{});var U=i(_);re=s(U,"Generally, we recommend using the "),L=l(U,"CODE",{});var M=i(L);E=s(M,"AutoTokenizer"),M.forEach(r),Z=s(U," class and the "),V=l(U,"CODE",{});var se=i(V);K=s(se,"AutoModelFor"),se.forEach(r),ee=s(U," class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),S=l(U,"A",{href:!0});var ie=i(S);te=s(ie,"tutorial"),ie.forEach(r),h=s(U,", learn how to use your newly loaded tokenizer, image processor, feature extractor and processor to preprocess a dataset for fine-tuning."),U.forEach(r),this.h()},h(){$(b,"href","model_doc/auto"),$(A,"href","/docs/transformers/v4.25.1/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),$(S,"href","preprocessing")},m(c,g){p(c,o,g),t(o,y),t(o,f),t(f,k),t(o,j),t(o,b),t(b,B),t(o,z),t(o,A),t(A,x),t(o,P),p(c,C,g),D(T,c,g),p(c,Q,g),p(c,q,g),t(q,X),p(c,Y,g),D(F,c,g),p(c,W,g),D(w,c,g),p(c,J,g),p(c,_,g),t(_,re),t(_,L),t(L,E),t(_,Z),t(_,V),t(V,K),t(_,ee),t(_,S),t(S,te),t(_,h),v=!0},p(c,g){const ae={};g&2&&(ae.$$scope={dirty:g,ctx:c}),w.$set(ae)},i(c){v||(H(T.$$.fragment,c),H(F.$$.fragment,c),H(w.$$.fragment,c),v=!0)},o(c){G(T.$$.fragment,c),G(F.$$.fragment,c),G(w.$$.fragment,c),v=!1},d(c){c&&r(o),c&&r(C),R(T,c),c&&r(Q),c&&r(q),c&&r(Y),R(F,c),c&&r(W),R(w,c),c&&r(J),c&&r(_)}}}function Ur(oe){let o,y;return o=new Lr({props:{$$slots:{default:[Vr]},$$scope:{ctx:oe}}}),{c(){N(o.$$.fragment)},l(f){O(o.$$.fragment,f)},m(f,k){D(o,f,k),y=!0},p(f,k){const j={};k&2&&(j.$$scope={dirty:k,ctx:f}),o.$set(j)},i(f){y||(H(o.$$.fragment,f),y=!0)},o(f){G(o.$$.fragment,f),y=!1},d(f){R(o,f)}}}function Wr(oe){let o,y,f,k,j,b,B,z,A,x,P,C,T,Q,q,X,Y,F,W,w,J,_,re,L,E,Z,V,K,ee,S,te;return T=new de({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>)`}}),F=new de({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 "),f=n("code"),k=a("TFAutoModelFor"),j=a(" classes let you load a pretrained model for a given task (see "),b=n("a"),B=a("here"),z=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()"),P=a(":"),C=m(),N(T.$$.fragment),Q=m(),q=n("p"),X=a("Easily reuse the same checkpoint to load an architecture for a different task:"),Y=m(),N(F.$$.fragment),W=m(),w=n("p"),J=a("Generally, we recommend using the "),_=n("code"),re=a("AutoTokenizer"),L=a(" class and the "),E=n("code"),Z=a("TFAutoModelFor"),V=a(" class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),K=n("a"),ee=a("tutorial"),S=a(", learn how to use your newly loaded tokenizer, image processor, feature extractor and processor to preprocess a dataset for fine-tuning."),this.h()},l(h){o=l(h,"P",{});var v=i(o);y=s(v,"Finally, the "),f=l(v,"CODE",{});var c=i(f);k=s(c,"TFAutoModelFor"),c.forEach(r),j=s(v," classes let you load a pretrained model for a given task (see "),b=l(v,"A",{href:!0});var g=i(b);B=s(g,"here"),g.forEach(r),z=s(v," for a complete list of available tasks). For example, load a model for sequence classification with "),A=l(v,"A",{href:!0});var ae=i(A);x=s(ae,"TFAutoModelForSequenceClassification.from_pretrained()"),ae.forEach(r),P=s(v,":"),v.forEach(r),C=d(h),O(T.$$.fragment,h),Q=d(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=d(h),O(F.$$.fragment,h),W=d(h),w=l(h,"P",{});var I=i(w);J=s(I,"Generally, we recommend using the "),_=l(I,"CODE",{});var le=i(_);re=s(le,"AutoTokenizer"),le.forEach(r),L=s(I," class and the "),E=l(I,"CODE",{});var U=i(E);Z=s(U,"TFAutoModelFor"),U.forEach(r),V=s(I," class to load pretrained instances of models. This will ensure you load the correct architecture every time. In the next "),K=l(I,"A",{href:!0});var M=i(K);ee=s(M,"tutorial"),M.forEach(r),S=s(I,", learn how to use your newly loaded tokenizer, image processor, feature extractor and processor to preprocess a dataset for fine-tuning."),I.forEach(r),this.h()},h(){$(b,"href","model_doc/auto"),$(A,"href","/docs/transformers/v4.25.1/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),$(K,"href","preprocessing")},m(h,v){p(h,o,v),t(o,y),t(o,f),t(f,k),t(o,j),t(o,b),t(b,B),t(o,z),t(o,A),t(A,x),t(o,P),p(h,C,v),D(T,h,v),p(h,Q,v),p(h,q,v),t(q,X),p(h,Y,v),D(F,h,v),p(h,W,v),p(h,w,v),t(w,J),t(w,_),t(_,re),t(w,L),t(w,E),t(E,Z),t(w,V),t(w,K),t(K,ee),t(w,S),te=!0},p:Hr,i(h){te||(H(T.$$.fragment,h),H(F.$$.fragment,h),te=!0)},o(h){G(T.$$.fragment,h),G(F.$$.fragment,h),te=!1},d(h){h&&r(o),h&&r(C),R(T,h),h&&r(Q),h&&r(q),h&&r(Y),R(F,h),h&&r(W),h&&r(w)}}}function Jr(oe){let o,y;return o=new Lr({props:{$$slots:{default:[Wr]},$$scope:{ctx:oe}}}),{c(){N(o.$$.fragment)},l(f){O(o.$$.fragment,f)},m(f,k){D(o,f,k),y=!0},p(f,k){const j={};k&2&&(j.$$scope={dirty:k,ctx:f}),o.$set(j)},i(f){y||(H(o.$$.fragment,f),y=!0)},o(f){G(o.$$.fragment,f),y=!1},d(f){R(o,f)}}}function Kr(oe){let o,y,f,k,j,b,B,z,A,x,P,C,T,Q,q,X,Y,F,W,w,J,_,re,L,E,Z,V,K,ee,S,te,h,v,c,g,ae,ne,I,le,U,M,se,ie,ce,Pt,Ve,Tt,tt,Le,qt,rt,$e,Ct,Se,Mt,zt,at,Ee,st,Ie,Lt,ot,je,nt,fe,ve,Ue,Fe,St,We,It,lt,Ne,Nt,it,xe,ct,ue,_e,Je,Pe,Ot,Ke,Dt,pt,Oe,Ht,ft,ge,Gt,De,Rt,Bt,ut,Te,ht,he,ke,Qe,qe,Vt,Xe,Ut,mt,we,Wt,He,Jt,Kt,dt,be,Qt,Ge,Xt,Yt,$t,Ce,vt,me,ye,Ye,Me,Zt,Ze,er,_t,Ae,gt;return b=new Be({}),w=new zr({props:{$$slots:{default:[Rr]},$$scope:{ctx:oe}}}),ce=new Be({}),Ee=new de({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>)`}}),je=new de({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>]}`}}),Fe=new Be({}),xe=new de({props:{code:`from transformers import AutoImageProcessor

image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor

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