import{S as Sa,i as ja,s as Ga,e as i,k as c,w as z,t as l,M as Va,c as s,d as t,m,a as n,x as O,h as r,b as f,N as qa,G as a,g as u,y as K,L as Ya,q as ee,o as te,B as ae,v as Xa}from"../../chunks/vendor-hf-doc-builder.js";import{I as la}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as sa}from"../../chunks/CodeBlock-hf-doc-builder.js";import{P as Ha}from"../../chunks/PipelineTag-hf-doc-builder.js";function Qa(ra){let b,Ae,y,T,be,D,lt,ye,st,Ie,w,E,we,P,rt,_e,nt,Me,p,ft,R,ut,ct,oe,mt,pt,De,h,C,ht,Z,dt,vt,gt,x,bt,L,yt,wt,_t,W,Tt,N,Et,kt,Pe,ie,$t,Re,le,Te,At,Ce,k,na,Ze,se,It,xe,re,Mt,Le,B,We,ne,Dt,Ne,$,Pt,Ee,Rt,Ct,Be,J,Je,A,Zt,U,xt,Lt,Ue,F,Fe,d,Wt,S,Nt,Bt,j,Jt,Ut,Se,I,Ft,fe,St,jt,je,v,Gt,G,Vt,qt,V,Yt,Xt,Ge,_,M,ke,q,Ht,$e,Qt,Ve,ue,zt,qe,Y,Ye,ce,g,me,Ot,Kt,X,ea,ta,H,aa,oa,Xe,pe,ia,He;return D=new la({}),P=new la({}),B=new sa({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsLmZyb21fcHJldHJhaW5lZCglMjJtaWNyb3NvZnQlMkZkaXQtYmFzZSUyMik=",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>)`}}),J=new sa({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJlaXRGb3JNYXNrZWRJbWFnZU1vZGVsaW5nJTBBJTBBbW9kZWwlMjAlM0QlMjBCZWl0Rm9yTWFza2VkSW1hZ2VNb2RlbGluZy5mcm9tX3ByZXRyYWluZWQoJTIybWljcm9zb2Z0JTJGZGl0LWJhc2UlMjIp",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>)`}}),F=new sa({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMm1pY3Jvc29mdCUyRmRpdC1iYXNlLWZpbmV0dW5lZC1ydmxjZGlwJTIyKQ==",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>)`}}),q=new la({}),Y=new Ha({props:{pipeline:"image-classification"}}),{c(){b=i("meta"),Ae=c(),y=i("h1"),T=i("a"),be=i("span"),z(D.$$.fragment),lt=c(),ye=i("span"),st=l("DiT"),Ie=c(),w=i("h2"),E=i("a"),we=i("span"),z(P.$$.fragment),rt=c(),_e=i("span"),nt=l("Overview"),Me=c(),p=i("p"),ft=l("DiT was proposed in "),R=i("a"),ut=l("DiT: Self-supervised Pre-training for Document Image Transformer"),ct=l(` by Junlong Li, Yiheng Xu, Tengchao Lv, Lei Cui, Cha Zhang, Furu Wei.
DiT applies the self-supervised objective of `),oe=i("a"),mt=l("BEiT"),pt=l(" (BERT pre-training of Image Transformers) to 42 million document images, allowing for state-of-the-art results on tasks including:"),De=c(),h=i("ul"),C=i("li"),ht=l("document image classification: the "),Z=i("a"),dt=l("RVL-CDIP"),vt=l(` dataset (a collection of
400,000 images belonging to one of 16 classes).`),gt=c(),x=i("li"),bt=l("document layout analysis: the "),L=i("a"),yt=l("PubLayNet"),wt=l(` dataset (a collection of more
than 360,000 document images constructed by automatically parsing PubMed XML files).`),_t=c(),W=i("li"),Tt=l("table detection: the "),N=i("a"),Et=l("ICDAR 2019 cTDaR"),kt=l(` dataset (a collection of
600 training images and 240 testing images).`),Pe=c(),ie=i("p"),$t=l("The abstract from the paper is the following:"),Re=c(),le=i("p"),Te=i("em"),At=l("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)."),Ce=c(),k=i("img"),Ze=c(),se=i("small"),It=l("Summary of the approach. Taken from the [original paper](https://arxiv.org/abs/2203.02378)."),xe=c(),re=i("p"),Mt=l("One can directly use the weights of DiT with the AutoModel API:"),Le=c(),z(B.$$.fragment),We=c(),ne=i("p"),Dt=l("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."),Ne=c(),$=i("p"),Pt=l("To include the head, you can load the weights into a "),Ee=i("code"),Rt=l("BeitForMaskedImageModeling"),Ct=l(" model, like so:"),Be=c(),z(J.$$.fragment),Je=c(),A=i("p"),Zt=l("You can also load a fine-tuned model from the "),U=i("a"),xt=l("hub"),Lt=l(", like so:"),Ue=c(),z(F.$$.fragment),Fe=c(),d=i("p"),Wt=l("This particular checkpoint was fine-tuned on "),S=i("a"),Nt=l("RVL-CDIP"),Bt=l(`, an important benchmark for document image classification.
A notebook that illustrates inference for document image classification can be found `),j=i("a"),Jt=l("here"),Ut=l("."),Se=c(),I=i("p"),Ft=l("As DiT\u2019s architecture is equivalent to that of BEiT, one can refer to "),fe=i("a"),St=l("BEiT\u2019s documentation page"),jt=l(" for all tips, code examples and notebooks."),je=c(),v=i("p"),Gt=l("This model was contributed by "),G=i("a"),Vt=l("nielsr"),qt=l(". The original code can be found "),V=i("a"),Yt=l("here"),Xt=l("."),Ge=c(),_=i("h2"),M=i("a"),ke=i("span"),z(q.$$.fragment),Ht=c(),$e=i("span"),Qt=l("Resources"),Ve=c(),ue=i("p"),zt=l("A list of official Hugging Face and community (indicated by \u{1F30E}) resources to help you get started with DiT."),qe=c(),z(Y.$$.fragment),Ye=c(),ce=i("ul"),g=i("li"),me=i("a"),Ot=l("BeitForImageClassification"),Kt=l(" is supported by this "),X=i("a"),ea=l("example script"),ta=l(" and "),H=i("a"),aa=l("notebook"),oa=l("."),Xe=c(),pe=i("p"),ia=l("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=Va('[data-svelte="svelte-1phssyn"]',document.head);b=s(o,"META",{name:!0,content:!0}),o.forEach(t),Ae=m(e),y=s(e,"H1",{class:!0});var Qe=n(y);T=s(Qe,"A",{id:!0,class:!0,href:!0});var fa=n(T);be=s(fa,"SPAN",{});var ua=n(be);O(D.$$.fragment,ua),ua.forEach(t),fa.forEach(t),lt=m(Qe),ye=s(Qe,"SPAN",{});var ca=n(ye);st=r(ca,"DiT"),ca.forEach(t),Qe.forEach(t),Ie=m(e),w=s(e,"H2",{class:!0});var ze=n(w);E=s(ze,"A",{id:!0,class:!0,href:!0});var ma=n(E);we=s(ma,"SPAN",{});var pa=n(we);O(P.$$.fragment,pa),pa.forEach(t),ma.forEach(t),rt=m(ze),_e=s(ze,"SPAN",{});var ha=n(_e);nt=r(ha,"Overview"),ha.forEach(t),ze.forEach(t),Me=m(e),p=s(e,"P",{});var he=n(p);ft=r(he,"DiT was proposed in "),R=s(he,"A",{href:!0,rel:!0});var da=n(R);ut=r(da,"DiT: Self-supervised Pre-training for Document Image Transformer"),da.forEach(t),ct=r(he,` by Junlong Li, Yiheng Xu, Tengchao Lv, Lei Cui, Cha Zhang, Furu Wei.
DiT applies the self-supervised objective of `),oe=s(he,"A",{href:!0});var va=n(oe);mt=r(va,"BEiT"),va.forEach(t),pt=r(he," (BERT pre-training of Image Transformers) to 42 million document images, allowing for state-of-the-art results on tasks including:"),he.forEach(t),De=m(e),h=s(e,"UL",{});var de=n(h);C=s(de,"LI",{});var Oe=n(C);ht=r(Oe,"document image classification: the "),Z=s(Oe,"A",{href:!0,rel:!0});var ga=n(Z);dt=r(ga,"RVL-CDIP"),ga.forEach(t),vt=r(Oe,` dataset (a collection of
400,000 images belonging to one of 16 classes).`),Oe.forEach(t),gt=m(de),x=s(de,"LI",{});var Ke=n(x);bt=r(Ke,"document layout analysis: the "),L=s(Ke,"A",{href:!0,rel:!0});var ba=n(L);yt=r(ba,"PubLayNet"),ba.forEach(t),wt=r(Ke,` dataset (a collection of more
than 360,000 document images constructed by automatically parsing PubMed XML files).`),Ke.forEach(t),_t=m(de),W=s(de,"LI",{});var et=n(W);Tt=r(et,"table detection: the "),N=s(et,"A",{href:!0,rel:!0});var ya=n(N);Et=r(ya,"ICDAR 2019 cTDaR"),ya.forEach(t),kt=r(et,` dataset (a collection of
600 training images and 240 testing images).`),et.forEach(t),de.forEach(t),Pe=m(e),ie=s(e,"P",{});var wa=n(ie);$t=r(wa,"The abstract from the paper is the following:"),wa.forEach(t),Re=m(e),le=s(e,"P",{});var _a=n(le);Te=s(_a,"EM",{});var Ta=n(Te);At=r(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),_a.forEach(t),Ce=m(e),k=s(e,"IMG",{src:!0,alt:!0,width:!0}),Ze=m(e),se=s(e,"SMALL",{});var Ea=n(se);It=r(Ea,"Summary of the approach. Taken from the [original paper](https://arxiv.org/abs/2203.02378)."),Ea.forEach(t),xe=m(e),re=s(e,"P",{});var ka=n(re);Mt=r(ka,"One can directly use the weights of DiT with the AutoModel API:"),ka.forEach(t),Le=m(e),O(B.$$.fragment,e),We=m(e),ne=s(e,"P",{});var $a=n(ne);Dt=r($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),Ne=m(e),$=s(e,"P",{});var tt=n($);Pt=r(tt,"To include the head, you can load the weights into a "),Ee=s(tt,"CODE",{});var Aa=n(Ee);Rt=r(Aa,"BeitForMaskedImageModeling"),Aa.forEach(t),Ct=r(tt," model, like so:"),tt.forEach(t),Be=m(e),O(J.$$.fragment,e),Je=m(e),A=s(e,"P",{});var at=n(A);Zt=r(at,"You can also load a fine-tuned model from the "),U=s(at,"A",{href:!0,rel:!0});var Ia=n(U);xt=r(Ia,"hub"),Ia.forEach(t),Lt=r(at,", like so:"),at.forEach(t),Ue=m(e),O(F.$$.fragment,e),Fe=m(e),d=s(e,"P",{});var ve=n(d);Wt=r(ve,"This particular checkpoint was fine-tuned on "),S=s(ve,"A",{href:!0,rel:!0});var Ma=n(S);Nt=r(Ma,"RVL-CDIP"),Ma.forEach(t),Bt=r(ve,`, an important benchmark for document image classification.
A notebook that illustrates inference for document image classification can be found `),j=s(ve,"A",{href:!0,rel:!0});var Da=n(j);Jt=r(Da,"here"),Da.forEach(t),Ut=r(ve,"."),ve.forEach(t),Se=m(e),I=s(e,"P",{});var ot=n(I);Ft=r(ot,"As DiT\u2019s architecture is equivalent to that of BEiT, one can refer to "),fe=s(ot,"A",{href:!0});var Pa=n(fe);St=r(Pa,"BEiT\u2019s documentation page"),Pa.forEach(t),jt=r(ot," for all tips, code examples and notebooks."),ot.forEach(t),je=m(e),v=s(e,"P",{});var ge=n(v);Gt=r(ge,"This model was contributed by "),G=s(ge,"A",{href:!0,rel:!0});var Ra=n(G);Vt=r(Ra,"nielsr"),Ra.forEach(t),qt=r(ge,". The original code can be found "),V=s(ge,"A",{href:!0,rel:!0});var Ca=n(V);Yt=r(Ca,"here"),Ca.forEach(t),Xt=r(ge,"."),ge.forEach(t),Ge=m(e),_=s(e,"H2",{class:!0});var it=n(_);M=s(it,"A",{id:!0,class:!0,href:!0});var Za=n(M);ke=s(Za,"SPAN",{});var xa=n(ke);O(q.$$.fragment,xa),xa.forEach(t),Za.forEach(t),Ht=m(it),$e=s(it,"SPAN",{});var La=n($e);Qt=r(La,"Resources"),La.forEach(t),it.forEach(t),Ve=m(e),ue=s(e,"P",{});var Wa=n(ue);zt=r(Wa,"A list of official Hugging Face and community (indicated by \u{1F30E}) resources to help you get started with DiT."),Wa.forEach(t),qe=m(e),O(Y.$$.fragment,e),Ye=m(e),ce=s(e,"UL",{});var Na=n(ce);g=s(Na,"LI",{});var Q=n(g);me=s(Q,"A",{href:!0});var Ba=n(me);Ot=r(Ba,"BeitForImageClassification"),Ba.forEach(t),Kt=r(Q," is supported by this "),X=s(Q,"A",{href:!0,rel:!0});var Ja=n(X);ea=r(Ja,"example script"),Ja.forEach(t),ta=r(Q," and "),H=s(Q,"A",{href:!0,rel:!0});var Ua=n(H);aa=r(Ua,"notebook"),Ua.forEach(t),oa=r(Q,"."),Q.forEach(t),Na.forEach(t),Xe=m(e),pe=s(e,"P",{});var Fa=n(pe);ia=r(Fa,"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."),Fa.forEach(t),this.h()},h(){f(b,"name","hf:doc:metadata"),f(b,"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(y,"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(w,"class","relative group"),f(R,"href","https://arxiv.org/abs/2203.02378"),f(R,"rel","nofollow"),f(oe,"href","beit"),f(Z,"href","https://www.cs.cmu.edu/~aharley/rvl-cdip/"),f(Z,"rel","nofollow"),f(L,"href","https://github.com/ibm-aur-nlp/PubLayNet"),f(L,"rel","nofollow"),f(N,"href","https://github.com/cndplab-founder/ICDAR2019_cTDaR"),f(N,"rel","nofollow"),qa(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(U,"href","https://huggingface.co/models?other=dit"),f(U,"rel","nofollow"),f(S,"href","https://www.cs.cmu.edu/~aharley/rvl-cdip/"),f(S,"rel","nofollow"),f(j,"href","https://github.com/NielsRogge/Transformers-Tutorials/blob/master/DiT/Inference_with_DiT_(Document_Image_Transformer)_for_document_image_classification.ipynb"),f(j,"rel","nofollow"),f(fe,"href","beit"),f(G,"href","https://huggingface.co/nielsr"),f(G,"rel","nofollow"),f(V,"href","https://github.com/microsoft/unilm/tree/master/dit"),f(V,"rel","nofollow"),f(M,"id","resources"),f(M,"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(M,"href","#resources"),f(_,"class","relative group"),f(me,"href","/docs/transformers/v4.30.0/en/model_doc/beit#transformers.BeitForImageClassification"),f(X,"href","https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification"),f(X,"rel","nofollow"),f(H,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb"),f(H,"rel","nofollow")},m(e,o){a(document.head,b),u(e,Ae,o),u(e,y,o),a(y,T),a(T,be),K(D,be,null),a(y,lt),a(y,ye),a(ye,st),u(e,Ie,o),u(e,w,o),a(w,E),a(E,we),K(P,we,null),a(w,rt),a(w,_e),a(_e,nt),u(e,Me,o),u(e,p,o),a(p,ft),a(p,R),a(R,ut),a(p,ct),a(p,oe),a(oe,mt),a(p,pt),u(e,De,o),u(e,h,o),a(h,C),a(C,ht),a(C,Z),a(Z,dt),a(C,vt),a(h,gt),a(h,x),a(x,bt),a(x,L),a(L,yt),a(x,wt),a(h,_t),a(h,W),a(W,Tt),a(W,N),a(N,Et),a(W,kt),u(e,Pe,o),u(e,ie,o),a(ie,$t),u(e,Re,o),u(e,le,o),a(le,Te),a(Te,At),u(e,Ce,o),u(e,k,o),u(e,Ze,o),u(e,se,o),a(se,It),u(e,xe,o),u(e,re,o),a(re,Mt),u(e,Le,o),K(B,e,o),u(e,We,o),u(e,ne,o),a(ne,Dt),u(e,Ne,o),u(e,$,o),a($,Pt),a($,Ee),a(Ee,Rt),a($,Ct),u(e,Be,o),K(J,e,o),u(e,Je,o),u(e,A,o),a(A,Zt),a(A,U),a(U,xt),a(A,Lt),u(e,Ue,o),K(F,e,o),u(e,Fe,o),u(e,d,o),a(d,Wt),a(d,S),a(S,Nt),a(d,Bt),a(d,j),a(j,Jt),a(d,Ut),u(e,Se,o),u(e,I,o),a(I,Ft),a(I,fe),a(fe,St),a(I,jt),u(e,je,o),u(e,v,o),a(v,Gt),a(v,G),a(G,Vt),a(v,qt),a(v,V),a(V,Yt),a(v,Xt),u(e,Ge,o),u(e,_,o),a(_,M),a(M,ke),K(q,ke,null),a(_,Ht),a(_,$e),a($e,Qt),u(e,Ve,o),u(e,ue,o),a(ue,zt),u(e,qe,o),K(Y,e,o),u(e,Ye,o),u(e,ce,o),a(ce,g),a(g,me),a(me,Ot),a(g,Kt),a(g,X),a(X,ea),a(g,ta),a(g,H),a(H,aa),a(g,oa),u(e,Xe,o),u(e,pe,o),a(pe,ia),He=!0},p:Ya,i(e){He||(ee(D.$$.fragment,e),ee(P.$$.fragment,e),ee(B.$$.fragment,e),ee(J.$$.fragment,e),ee(F.$$.fragment,e),ee(q.$$.fragment,e),ee(Y.$$.fragment,e),He=!0)},o(e){te(D.$$.fragment,e),te(P.$$.fragment,e),te(B.$$.fragment,e),te(J.$$.fragment,e),te(F.$$.fragment,e),te(q.$$.fragment,e),te(Y.$$.fragment,e),He=!1},d(e){t(b),e&&t(Ae),e&&t(y),ae(D),e&&t(Ie),e&&t(w),ae(P),e&&t(Me),e&&t(p),e&&t(De),e&&t(h),e&&t(Pe),e&&t(ie),e&&t(Re),e&&t(le),e&&t(Ce),e&&t(k),e&&t(Ze),e&&t(se),e&&t(xe),e&&t(re),e&&t(Le),ae(B,e),e&&t(We),e&&t(ne),e&&t(Ne),e&&t($),e&&t(Be),ae(J,e),e&&t(Je),e&&t(A),e&&t(Ue),ae(F,e),e&&t(Fe),e&&t(d),e&&t(Se),e&&t(I),e&&t(je),e&&t(v),e&&t(Ge),e&&t(_),ae(q),e&&t(Ve),e&&t(ue),e&&t(qe),ae(Y,e),e&&t(Ye),e&&t(ce),e&&t(Xe),e&&t(pe)}}}const za={local:"dit",sections:[{local:"overview",title:"Overview"},{local:"resources",title:"Resources"}],title:"DiT"};function Oa(ra){return Xa(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class oo extends Sa{constructor(b){super();ja(this,b,Oa,Qa,Ga,{})}}export{oo as default,za as metadata};
