import{S as Va,i as Ha,s as Wa,e as i,k as m,w as z,t as r,M as Xa,c as s,d as t,m as c,a as n,x as K,h as l,b as f,N as Ya,G as a,g as u,y as Q,L as Ja,q as ee,o as te,B as ae,v as Ua}from"../../chunks/vendor-hf-doc-builder.js";import{I as ra}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as sa}from"../../chunks/CodeBlock-hf-doc-builder.js";import{P as Ga}from"../../chunks/PipelineTag-hf-doc-builder.js";function Za(la){let w,Ae,b,T,we,P,rt,be,st,Ie,_,E,_e,M,lt,ye,nt,De,p,ft,x,ut,mt,oe,ct,pt,Pe,d,L,dt,C,ht,gt,vt,B,wt,R,bt,_t,yt,F,Tt,q,Et,kt,Me,ie,$t,xe,re,Te,At,Le,k,na,Ce,se,It,Be,le,Dt,Re,S,Fe,ne,Pt,qe,$,Mt,Ee,xt,Lt,Se,N,Ne,A,Ct,j,Bt,Rt,je,O,Oe,h,Ft,V,qt,St,H,Nt,jt,Ve,I,Ot,fe,Vt,Ht,He,g,Wt,W,Xt,Yt,X,Jt,Ut,We,y,D,ke,Y,Gt,$e,Zt,Xe,ue,zt,Ye,J,Je,me,v,ce,Kt,Qt,U,ea,ta,G,aa,oa,Ue,pe,ia,Ge;return P=new ra({}),M=new ra({}),S=new sa({props:{code:`from transformers import AutoModel

model = AutoModel.from_pretrained("microsoft/dit-base")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModel

model = AutoModel.from_pretrained(<span class="hljs-string">&quot;microsoft/dit-base&quot;</span>)`}}),N=new sa({props:{code:`from transformers import BeitForMaskedImageModeling

model = BeitForMaskedImageModeling.from_pretrained("microsoft/dit-base")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BeitForMaskedImageModeling

model = BeitForMaskedImageModeling.from_pretrained(<span class="hljs-string">&quot;microsoft/dit-base&quot;</span>)`}}),O=new sa({props:{code:`from transformers import AutoModelForImageClassification

model = AutoModelForImageClassification.from_pretrained("microsoft/dit-base-finetuned-rvlcdip")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageClassification

model = AutoModelForImageClassification.from_pretrained(<span class="hljs-string">&quot;microsoft/dit-base-finetuned-rvlcdip&quot;</span>)`}}),Y=new ra({}),J=new Ga({props:{pipeline:"image-classification"}}),{c(){w=i("meta"),Ae=m(),b=i("h1"),T=i("a"),we=i("span"),z(P.$$.fragment),rt=m(),be=i("span"),st=r("DiT"),Ie=m(),_=i("h2"),E=i("a"),_e=i("span"),z(M.$$.fragment),lt=m(),ye=i("span"),nt=r("Overview"),De=m(),p=i("p"),ft=r("DiT was proposed in "),x=i("a"),ut=r("DiT: Self-supervised Pre-training for Document Image Transformer"),mt=r(` by Junlong Li, Yiheng Xu, Tengchao Lv, Lei Cui, Cha Zhang, Furu Wei.
DiT applies the self-supervised objective of `),oe=i("a"),ct=r("BEiT"),pt=r(" (BERT pre-training of Image Transformers) to 42 million document images, allowing for state-of-the-art results on tasks including:"),Pe=m(),d=i("ul"),L=i("li"),dt=r("document image classification: the "),C=i("a"),ht=r("RVL-CDIP"),gt=r(` dataset (a collection of
400,000 images belonging to one of 16 classes).`),vt=m(),B=i("li"),wt=r("document layout analysis: the "),R=i("a"),bt=r("PubLayNet"),_t=r(` dataset (a collection of more
than 360,000 document images constructed by automatically parsing PubMed XML files).`),yt=m(),F=i("li"),Tt=r("table detection: the "),q=i("a"),Et=r("ICDAR 2019 cTDaR"),kt=r(` dataset (a collection of
600 training images and 240 testing images).`),Me=m(),ie=i("p"),$t=r("The abstract from the paper is the following:"),xe=m(),re=i("p"),Te=i("em"),At=r("Image Transformer has recently achieved significant progress for natural image understanding, either using supervised (ViT, DeiT, etc.) or self-supervised (BEiT, MAE, etc.) pre-training techniques. In this paper, we propose DiT, a self-supervised pre-trained Document Image Transformer model using large-scale unlabeled text images for Document AI tasks, which is essential since no supervised counterparts ever exist due to the lack of human labeled document images. We leverage DiT as the backbone network in a variety of vision-based Document AI tasks, including document image classification, document layout analysis, as well as table detection. Experiment results have illustrated that the self-supervised pre-trained DiT model achieves new state-of-the-art results on these downstream tasks, e.g. document image classification (91.11 \u2192 92.69), document layout analysis (91.0 \u2192 94.9) and table detection (94.23 \u2192 96.55)."),Le=m(),k=i("img"),Ce=m(),se=i("small"),It=r("Summary of the approach. Taken from the [original paper](https://arxiv.org/abs/2203.02378)."),Be=m(),le=i("p"),Dt=r("One can directly use the weights of DiT with the AutoModel API:"),Re=m(),z(S.$$.fragment),Fe=m(),ne=i("p"),Pt=r("This will load the model pre-trained on masked image modeling. Note that this won\u2019t include the language modeling head on top, used to predict visual tokens."),qe=m(),$=i("p"),Mt=r("To include the head, you can load the weights into a "),Ee=i("code"),xt=r("BeitForMaskedImageModeling"),Lt=r(" model, like so:"),Se=m(),z(N.$$.fragment),Ne=m(),A=i("p"),Ct=r("You can also load a fine-tuned model from the "),j=i("a"),Bt=r("hub"),Rt=r(", like so:"),je=m(),z(O.$$.fragment),Oe=m(),h=i("p"),Ft=r("This particular checkpoint was fine-tuned on "),V=i("a"),qt=r("RVL-CDIP"),St=r(`, an important benchmark for document image classification.
A notebook that illustrates inference for document image classification can be found `),H=i("a"),Nt=r("here"),jt=r("."),Ve=m(),I=i("p"),Ot=r("As DiT\u2019s architecture is equivalent to that of BEiT, one can refer to "),fe=i("a"),Vt=r("BEiT\u2019s documentation page"),Ht=r(" for all tips, code examples and notebooks."),He=m(),g=i("p"),Wt=r("This model was contributed by "),W=i("a"),Xt=r("nielsr"),Yt=r(". The original code can be found "),X=i("a"),Jt=r("here"),Ut=r("."),We=m(),y=i("h2"),D=i("a"),ke=i("span"),z(Y.$$.fragment),Gt=m(),$e=i("span"),Zt=r("Resources"),Xe=m(),ue=i("p"),zt=r("A list of official Hugging Face and community (indicated by \u{1F30E}) resources to help you get started with DiT."),Ye=m(),z(J.$$.fragment),Je=m(),me=i("ul"),v=i("li"),ce=i("a"),Kt=r("BeitForImageClassification"),Qt=r(" is supported by this "),U=i("a"),ea=r("example script"),ta=r(" and "),G=i("a"),aa=r("notebook"),oa=r("."),Ue=m(),pe=i("p"),ia=r("If you\u2019re interested in submitting a resource to be included here, please feel free to open a Pull Request and we\u2019ll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource."),this.h()},l(e){const o=Xa('[data-svelte="svelte-1phssyn"]',document.head);w=s(o,"META",{name:!0,content:!0}),o.forEach(t),Ae=c(e),b=s(e,"H1",{class:!0});var Ze=n(b);T=s(Ze,"A",{id:!0,class:!0,href:!0});var fa=n(T);we=s(fa,"SPAN",{});var ua=n(we);K(P.$$.fragment,ua),ua.forEach(t),fa.forEach(t),rt=c(Ze),be=s(Ze,"SPAN",{});var ma=n(be);st=l(ma,"DiT"),ma.forEach(t),Ze.forEach(t),Ie=c(e),_=s(e,"H2",{class:!0});var ze=n(_);E=s(ze,"A",{id:!0,class:!0,href:!0});var ca=n(E);_e=s(ca,"SPAN",{});var pa=n(_e);K(M.$$.fragment,pa),pa.forEach(t),ca.forEach(t),lt=c(ze),ye=s(ze,"SPAN",{});var da=n(ye);nt=l(da,"Overview"),da.forEach(t),ze.forEach(t),De=c(e),p=s(e,"P",{});var de=n(p);ft=l(de,"DiT was proposed in "),x=s(de,"A",{href:!0,rel:!0});var ha=n(x);ut=l(ha,"DiT: Self-supervised Pre-training for Document Image Transformer"),ha.forEach(t),mt=l(de,` by Junlong Li, Yiheng Xu, Tengchao Lv, Lei Cui, Cha Zhang, Furu Wei.
DiT applies the self-supervised objective of `),oe=s(de,"A",{href:!0});var ga=n(oe);ct=l(ga,"BEiT"),ga.forEach(t),pt=l(de," (BERT pre-training of Image Transformers) to 42 million document images, allowing for state-of-the-art results on tasks including:"),de.forEach(t),Pe=c(e),d=s(e,"UL",{});var he=n(d);L=s(he,"LI",{});var Ke=n(L);dt=l(Ke,"document image classification: the "),C=s(Ke,"A",{href:!0,rel:!0});var va=n(C);ht=l(va,"RVL-CDIP"),va.forEach(t),gt=l(Ke,` dataset (a collection of
400,000 images belonging to one of 16 classes).`),Ke.forEach(t),vt=c(he),B=s(he,"LI",{});var Qe=n(B);wt=l(Qe,"document layout analysis: the "),R=s(Qe,"A",{href:!0,rel:!0});var wa=n(R);bt=l(wa,"PubLayNet"),wa.forEach(t),_t=l(Qe,` dataset (a collection of more
than 360,000 document images constructed by automatically parsing PubMed XML files).`),Qe.forEach(t),yt=c(he),F=s(he,"LI",{});var et=n(F);Tt=l(et,"table detection: the "),q=s(et,"A",{href:!0,rel:!0});var ba=n(q);Et=l(ba,"ICDAR 2019 cTDaR"),ba.forEach(t),kt=l(et,` dataset (a collection of
600 training images and 240 testing images).`),et.forEach(t),he.forEach(t),Me=c(e),ie=s(e,"P",{});var _a=n(ie);$t=l(_a,"The abstract from the paper is the following:"),_a.forEach(t),xe=c(e),re=s(e,"P",{});var ya=n(re);Te=s(ya,"EM",{});var Ta=n(Te);At=l(Ta,"Image Transformer has recently achieved significant progress for natural image understanding, either using supervised (ViT, DeiT, etc.) or self-supervised (BEiT, MAE, etc.) pre-training techniques. In this paper, we propose DiT, a self-supervised pre-trained Document Image Transformer model using large-scale unlabeled text images for Document AI tasks, which is essential since no supervised counterparts ever exist due to the lack of human labeled document images. We leverage DiT as the backbone network in a variety of vision-based Document AI tasks, including document image classification, document layout analysis, as well as table detection. Experiment results have illustrated that the self-supervised pre-trained DiT model achieves new state-of-the-art results on these downstream tasks, e.g. document image classification (91.11 \u2192 92.69), document layout analysis (91.0 \u2192 94.9) and table detection (94.23 \u2192 96.55)."),Ta.forEach(t),ya.forEach(t),Le=c(e),k=s(e,"IMG",{src:!0,alt:!0,width:!0}),Ce=c(e),se=s(e,"SMALL",{});var Ea=n(se);It=l(Ea,"Summary of the approach. Taken from the [original paper](https://arxiv.org/abs/2203.02378)."),Ea.forEach(t),Be=c(e),le=s(e,"P",{});var ka=n(le);Dt=l(ka,"One can directly use the weights of DiT with the AutoModel API:"),ka.forEach(t),Re=c(e),K(S.$$.fragment,e),Fe=c(e),ne=s(e,"P",{});var $a=n(ne);Pt=l($a,"This will load the model pre-trained on masked image modeling. Note that this won\u2019t include the language modeling head on top, used to predict visual tokens."),$a.forEach(t),qe=c(e),$=s(e,"P",{});var tt=n($);Mt=l(tt,"To include the head, you can load the weights into a "),Ee=s(tt,"CODE",{});var Aa=n(Ee);xt=l(Aa,"BeitForMaskedImageModeling"),Aa.forEach(t),Lt=l(tt," model, like so:"),tt.forEach(t),Se=c(e),K(N.$$.fragment,e),Ne=c(e),A=s(e,"P",{});var at=n(A);Ct=l(at,"You can also load a fine-tuned model from the "),j=s(at,"A",{href:!0,rel:!0});var Ia=n(j);Bt=l(Ia,"hub"),Ia.forEach(t),Rt=l(at,", like so:"),at.forEach(t),je=c(e),K(O.$$.fragment,e),Oe=c(e),h=s(e,"P",{});var ge=n(h);Ft=l(ge,"This particular checkpoint was fine-tuned on "),V=s(ge,"A",{href:!0,rel:!0});var Da=n(V);qt=l(Da,"RVL-CDIP"),Da.forEach(t),St=l(ge,`, an important benchmark for document image classification.
A notebook that illustrates inference for document image classification can be found `),H=s(ge,"A",{href:!0,rel:!0});var Pa=n(H);Nt=l(Pa,"here"),Pa.forEach(t),jt=l(ge,"."),ge.forEach(t),Ve=c(e),I=s(e,"P",{});var ot=n(I);Ot=l(ot,"As DiT\u2019s architecture is equivalent to that of BEiT, one can refer to "),fe=s(ot,"A",{href:!0});var Ma=n(fe);Vt=l(Ma,"BEiT\u2019s documentation page"),Ma.forEach(t),Ht=l(ot," for all tips, code examples and notebooks."),ot.forEach(t),He=c(e),g=s(e,"P",{});var ve=n(g);Wt=l(ve,"This model was contributed by "),W=s(ve,"A",{href:!0,rel:!0});var xa=n(W);Xt=l(xa,"nielsr"),xa.forEach(t),Yt=l(ve,". The original code can be found "),X=s(ve,"A",{href:!0,rel:!0});var La=n(X);Jt=l(La,"here"),La.forEach(t),Ut=l(ve,"."),ve.forEach(t),We=c(e),y=s(e,"H2",{class:!0});var it=n(y);D=s(it,"A",{id:!0,class:!0,href:!0});var Ca=n(D);ke=s(Ca,"SPAN",{});var Ba=n(ke);K(Y.$$.fragment,Ba),Ba.forEach(t),Ca.forEach(t),Gt=c(it),$e=s(it,"SPAN",{});var Ra=n($e);Zt=l(Ra,"Resources"),Ra.forEach(t),it.forEach(t),Xe=c(e),ue=s(e,"P",{});var Fa=n(ue);zt=l(Fa,"A list of official Hugging Face and community (indicated by \u{1F30E}) resources to help you get started with DiT."),Fa.forEach(t),Ye=c(e),K(J.$$.fragment,e),Je=c(e),me=s(e,"UL",{});var qa=n(me);v=s(qa,"LI",{});var Z=n(v);ce=s(Z,"A",{href:!0});var Sa=n(ce);Kt=l(Sa,"BeitForImageClassification"),Sa.forEach(t),Qt=l(Z," is supported by this "),U=s(Z,"A",{href:!0,rel:!0});var Na=n(U);ea=l(Na,"example script"),Na.forEach(t),ta=l(Z," and "),G=s(Z,"A",{href:!0,rel:!0});var ja=n(G);aa=l(ja,"notebook"),ja.forEach(t),oa=l(Z,"."),Z.forEach(t),qa.forEach(t),Ue=c(e),pe=s(e,"P",{});var Oa=n(pe);ia=l(Oa,"If you\u2019re interested in submitting a resource to be included here, please feel free to open a Pull Request and we\u2019ll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource."),Oa.forEach(t),this.h()},h(){f(w,"name","hf:doc:metadata"),f(w,"content",JSON.stringify(za)),f(T,"id","dit"),f(T,"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"),f(T,"href","#dit"),f(b,"class","relative group"),f(E,"id","overview"),f(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"),f(E,"href","#overview"),f(_,"class","relative group"),f(x,"href","https://arxiv.org/abs/2203.02378"),f(x,"rel","nofollow"),f(oe,"href","beit"),f(C,"href","https://www.cs.cmu.edu/~aharley/rvl-cdip/"),f(C,"rel","nofollow"),f(R,"href","https://github.com/ibm-aur-nlp/PubLayNet"),f(R,"rel","nofollow"),f(q,"href","https://github.com/cndplab-founder/ICDAR2019_cTDaR"),f(q,"rel","nofollow"),Ya(k.src,na="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dit_architecture.jpg")||f(k,"src",na),f(k,"alt","drawing"),f(k,"width","600"),f(j,"href","https://huggingface.co/models?other=dit"),f(j,"rel","nofollow"),f(V,"href","https://www.cs.cmu.edu/~aharley/rvl-cdip/"),f(V,"rel","nofollow"),f(H,"href","https://github.com/NielsRogge/Transformers-Tutorials/blob/master/DiT/Inference_with_DiT_(Document_Image_Transformer)_for_document_image_classification.ipynb"),f(H,"rel","nofollow"),f(fe,"href","beit"),f(W,"href","https://huggingface.co/nielsr"),f(W,"rel","nofollow"),f(X,"href","https://github.com/microsoft/unilm/tree/master/dit"),f(X,"rel","nofollow"),f(D,"id","resources"),f(D,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(D,"href","#resources"),f(y,"class","relative group"),f(ce,"href","/docs/transformers/v4.27.1/en/model_doc/beit#transformers.BeitForImageClassification"),f(U,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification"),f(U,"rel","nofollow"),f(G,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb"),f(G,"rel","nofollow")},m(e,o){a(document.head,w),u(e,Ae,o),u(e,b,o),a(b,T),a(T,we),Q(P,we,null),a(b,rt),a(b,be),a(be,st),u(e,Ie,o),u(e,_,o),a(_,E),a(E,_e),Q(M,_e,null),a(_,lt),a(_,ye),a(ye,nt),u(e,De,o),u(e,p,o),a(p,ft),a(p,x),a(x,ut),a(p,mt),a(p,oe),a(oe,ct),a(p,pt),u(e,Pe,o),u(e,d,o),a(d,L),a(L,dt),a(L,C),a(C,ht),a(L,gt),a(d,vt),a(d,B),a(B,wt),a(B,R),a(R,bt),a(B,_t),a(d,yt),a(d,F),a(F,Tt),a(F,q),a(q,Et),a(F,kt),u(e,Me,o),u(e,ie,o),a(ie,$t),u(e,xe,o),u(e,re,o),a(re,Te),a(Te,At),u(e,Le,o),u(e,k,o),u(e,Ce,o),u(e,se,o),a(se,It),u(e,Be,o),u(e,le,o),a(le,Dt),u(e,Re,o),Q(S,e,o),u(e,Fe,o),u(e,ne,o),a(ne,Pt),u(e,qe,o),u(e,$,o),a($,Mt),a($,Ee),a(Ee,xt),a($,Lt),u(e,Se,o),Q(N,e,o),u(e,Ne,o),u(e,A,o),a(A,Ct),a(A,j),a(j,Bt),a(A,Rt),u(e,je,o),Q(O,e,o),u(e,Oe,o),u(e,h,o),a(h,Ft),a(h,V),a(V,qt),a(h,St),a(h,H),a(H,Nt),a(h,jt),u(e,Ve,o),u(e,I,o),a(I,Ot),a(I,fe),a(fe,Vt),a(I,Ht),u(e,He,o),u(e,g,o),a(g,Wt),a(g,W),a(W,Xt),a(g,Yt),a(g,X),a(X,Jt),a(g,Ut),u(e,We,o),u(e,y,o),a(y,D),a(D,ke),Q(Y,ke,null),a(y,Gt),a(y,$e),a($e,Zt),u(e,Xe,o),u(e,ue,o),a(ue,zt),u(e,Ye,o),Q(J,e,o),u(e,Je,o),u(e,me,o),a(me,v),a(v,ce),a(ce,Kt),a(v,Qt),a(v,U),a(U,ea),a(v,ta),a(v,G),a(G,aa),a(v,oa),u(e,Ue,o),u(e,pe,o),a(pe,ia),Ge=!0},p:Ja,i(e){Ge||(ee(P.$$.fragment,e),ee(M.$$.fragment,e),ee(S.$$.fragment,e),ee(N.$$.fragment,e),ee(O.$$.fragment,e),ee(Y.$$.fragment,e),ee(J.$$.fragment,e),Ge=!0)},o(e){te(P.$$.fragment,e),te(M.$$.fragment,e),te(S.$$.fragment,e),te(N.$$.fragment,e),te(O.$$.fragment,e),te(Y.$$.fragment,e),te(J.$$.fragment,e),Ge=!1},d(e){t(w),e&&t(Ae),e&&t(b),ae(P),e&&t(Ie),e&&t(_),ae(M),e&&t(De),e&&t(p),e&&t(Pe),e&&t(d),e&&t(Me),e&&t(ie),e&&t(xe),e&&t(re),e&&t(Le),e&&t(k),e&&t(Ce),e&&t(se),e&&t(Be),e&&t(le),e&&t(Re),ae(S,e),e&&t(Fe),e&&t(ne),e&&t(qe),e&&t($),e&&t(Se),ae(N,e),e&&t(Ne),e&&t(A),e&&t(je),ae(O,e),e&&t(Oe),e&&t(h),e&&t(Ve),e&&t(I),e&&t(He),e&&t(g),e&&t(We),e&&t(y),ae(Y),e&&t(Xe),e&&t(ue),e&&t(Ye),ae(J,e),e&&t(Je),e&&t(me),e&&t(Ue),e&&t(pe)}}}const za={local:"dit",sections:[{local:"overview",title:"Overview"},{local:"resources",title:"Resources"}],title:"DiT"};function Ka(la){return Ua(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class oo extends Va{constructor(w){super();Ha(this,w,Ka,Za,Wa,{})}}export{oo as default,za as metadata};
