import{S as ri,i as si,s as ai,e as a,k as c,w as b,t as r,M as ni,c as n,d as o,m as h,a as i,x as C,h as s,b as l,N as ii,G as e,g as p,y as w,q as k,o as O,B as y,v as li,L as oi}from"../../chunks/vendor-hf-doc-builder.js";import{T as ei}from"../../chunks/Tip-hf-doc-builder.js";import{D as re}from"../../chunks/Docstring-hf-doc-builder.js";import{C as Aa}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as jt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ti}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function di(W){let f,R,u,g,T;return g=new Aa({props:{code:`from transformers import TrOCRConfig, TrOCRForCausalLM

# Initializing a TrOCR-base style configuration
configuration = TrOCRConfig()

# Initializing a model (with random weights) from the TrOCR-base style configuration
model = TrOCRForCausalLM(configuration)

# Accessing the model configuration
configuration = model.config`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrOCRConfig, TrOCRForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a TrOCR-base style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = TrOCRConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the TrOCR-base style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TrOCRForCausalLM(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`}}),{c(){f=a("p"),R=r("Example:"),u=c(),b(g.$$.fragment)},l(m){f=n(m,"P",{});var _=i(f);R=s(_,"Example:"),_.forEach(o),u=h(m),C(g.$$.fragment,m)},m(m,_){p(m,f,_),e(f,R),p(m,u,_),w(g,m,_),T=!0},p:oi,i(m){T||(k(g.$$.fragment,m),T=!0)},o(m){O(g.$$.fragment,m),T=!1},d(m){m&&o(f),m&&o(u),y(g,m)}}}function ci(W){let f,R,u,g,T,m,_,q,I,P,j;return{c(){f=a("p"),R=r(`This class method is simply calling the feature extractor
`),u=a("a"),g=r("from_pretrained()"),T=r(`, image processor
`),m=a("a"),_=r("ImageProcessingMixin"),q=r(` and the tokenizer
`),I=a("code"),P=r("~tokenization_utils_base.PreTrainedTokenizer.from_pretrained"),j=r(` methods. Please refer to the docstrings of the
methods above for more information.`),this.h()},l(M){f=n(M,"P",{});var z=i(f);R=s(z,`This class method is simply calling the feature extractor
`),u=n(z,"A",{href:!0});var B=i(u);g=s(B,"from_pretrained()"),B.forEach(o),T=s(z,`, image processor
`),m=n(z,"A",{href:!0});var at=i(m);_=s(at,"ImageProcessingMixin"),at.forEach(o),q=s(z,` and the tokenizer
`),I=n(z,"CODE",{});var se=i(I);P=s(se,"~tokenization_utils_base.PreTrainedTokenizer.from_pretrained"),se.forEach(o),j=s(z,` methods. Please refer to the docstrings of the
methods above for more information.`),z.forEach(o),this.h()},h(){l(u,"href","/docs/transformers/v4.27.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained"),l(m,"href","/docs/transformers/v4.27.1/en/internal/image_processing_utils#transformers.ImageProcessingMixin")},m(M,z){p(M,f,z),e(f,R),e(f,u),e(u,g),e(f,T),e(f,m),e(m,_),e(f,q),e(f,I),e(I,P),e(f,j)},d(M){M&&o(f)}}}function hi(W){let f,R,u,g,T,m,_,q;return{c(){f=a("p"),R=r("This class method is simply calling "),u=a("a"),g=r("save_pretrained()"),T=r(` and
`),m=a("a"),_=r("save_pretrained()"),q=r(`. Please refer to the docstrings of the
methods above for more information.`),this.h()},l(I){f=n(I,"P",{});var P=i(f);R=s(P,"This class method is simply calling "),u=n(P,"A",{href:!0});var j=i(u);g=s(j,"save_pretrained()"),j.forEach(o),T=s(P,` and
`),m=n(P,"A",{href:!0});var M=i(m);_=s(M,"save_pretrained()"),M.forEach(o),q=s(P,`. Please refer to the docstrings of the
methods above for more information.`),P.forEach(o),this.h()},h(){l(u,"href","/docs/transformers/v4.27.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained"),l(m,"href","/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.save_pretrained")},m(I,P){p(I,f,P),e(f,R),e(f,u),e(u,g),e(f,T),e(f,m),e(m,_),e(f,q)},d(I){I&&o(f)}}}function mi(W){let f,R,u,g,T;return g=new Aa({props:{code:`from transformers import (
    TrOCRConfig,
    TrOCRProcessor,
    TrOCRForCausalLM,
    ViTConfig,
    ViTModel,
    VisionEncoderDecoderModel,
)
import requests
from PIL import Image

# TrOCR is a decoder model and should be used within a VisionEncoderDecoderModel
# init vision2text model with random weights
encoder = ViTModel(ViTConfig())
decoder = TrOCRForCausalLM(TrOCRConfig())
model = VisionEncoderDecoderModel(encoder=encoder, decoder=decoder)

# If you want to start from the pretrained model, load the checkpoint with \`VisionEncoderDecoderModel\`
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")

# load image from the IAM dataset
url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
pixel_values = processor(image, return_tensors="pt").pixel_values
text = "industry, ' Mr. Brown commented icily. ' Let us have a"

# training
model.config.decoder_start_token_id = processor.tokenizer.cls_token_id
model.config.pad_token_id = processor.tokenizer.pad_token_id
model.config.vocab_size = model.config.decoder.vocab_size

labels = processor.tokenizer(text, return_tensors="pt").input_ids
outputs = model(pixel_values, labels=labels)
loss = outputs.loss
round(loss.item(), 2)

# inference
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
generated_text`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> (
<span class="hljs-meta">... </span>    TrOCRConfig,
<span class="hljs-meta">... </span>    TrOCRProcessor,
<span class="hljs-meta">... </span>    TrOCRForCausalLM,
<span class="hljs-meta">... </span>    ViTConfig,
<span class="hljs-meta">... </span>    ViTModel,
<span class="hljs-meta">... </span>    VisionEncoderDecoderModel,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># TrOCR is a decoder model and should be used within a VisionEncoderDecoderModel</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># init vision2text model with random weights</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>encoder = ViTModel(ViTConfig())
<span class="hljs-meta">&gt;&gt;&gt; </span>decoder = TrOCRForCausalLM(TrOCRConfig())
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel(encoder=encoder, decoder=decoder)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># If you want to start from the pretrained model, load the checkpoint with \`VisionEncoderDecoderModel\`</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = TrOCRProcessor.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load image from the IAM dataset</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values
<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;industry, &#x27; Mr. Brown commented icily. &#x27; Let us have a&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># training</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.decoder_start_token_id = processor.tokenizer.cls_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.pad_token_id = processor.tokenizer.pad_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.vocab_size = model.config.decoder.vocab_size

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = processor.tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(pixel_values, labels=labels)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">round</span>(loss.item(), <span class="hljs-number">2</span>)
<span class="hljs-number">5.30</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># inference</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_ids = model.generate(pixel_values)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_text = processor.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_text
<span class="hljs-string">&#x27;industry, &quot; Mr. Brown commented icily. &quot; Let us have a&#x27;</span>`}}),{c(){f=a("p"),R=r("Example:"),u=c(),b(g.$$.fragment)},l(m){f=n(m,"P",{});var _=i(f);R=s(_,"Example:"),_.forEach(o),u=h(m),C(g.$$.fragment,m)},m(m,_){p(m,f,_),e(f,R),p(m,u,_),w(g,m,_),T=!0},p:oi,i(m){T||(k(g.$$.fragment,m),T=!0)},o(m){O(g.$$.fragment,m),T=!1},d(m){m&&o(f),m&&o(u),y(g,m)}}}function pi(W){let f,R,u,g,T,m,_,q,I,P,j,M,z,B,at,se,er,fo,H,tr,$e,or,rr,Re,sr,ar,uo,nt,nr,go,it,zt,ir,_o,ae,Fa,vo,ne,lr,lt,dr,cr,To,ie,hr,Lt,mr,pr,bo,G,fr,Ee,ur,gr,xe,_r,vr,Co,dt,Tr,wo,X,Pe,br,Me,Cr,wr,kr,V,Or,je,yr,$r,ze,Rr,Er,Le,xr,Pr,Mr,Ie,jr,ct,zr,Lr,ko,Y,le,It,De,Ir,Dt,Dr,Oo,U,qr,qt,Ar,Fr,ht,Vr,Nr,yo,v,Sr,At,Wr,Br,Ft,Hr,Gr,Vt,Xr,Ur,Nt,Zr,Jr,mt,Yr,Kr,St,Qr,es,Wt,ts,os,Bt,rs,ss,Ht,as,ns,$o,pt,Gt,is,Ro,qe,Eo,de,ls,Ae,ds,cs,xo,K,ce,Xt,Fe,hs,Ut,ms,Po,A,Ve,ps,Q,fs,ft,us,gs,Ne,_s,vs,Ts,ee,bs,ut,Cs,ws,gt,ks,Os,ys,he,Mo,te,me,Zt,Se,$s,Jt,Rs,jo,$,We,Es,Yt,xs,Ps,x,_t,Ms,js,Kt,zs,Ls,Qt,Is,Ds,eo,qs,As,to,Fs,Vs,Be,oo,Ns,Ss,Ws,vt,Bs,Hs,Gs,pe,He,Xs,N,Us,ro,Zs,Js,so,Ys,Ks,ao,Qs,ea,ta,Z,Ge,oa,no,ra,sa,fe,aa,J,Xe,na,Ue,ia,Tt,la,da,ca,ue,ha,ge,Ze,ma,Je,pa,bt,fa,ua,ga,_e,Ye,_a,Ke,va,Ct,Ta,ba,zo,oe,ve,io,Qe,Ca,lo,wa,Lo,F,et,ka,S,Oa,wt,ya,$a,co,Ra,Ea,kt,xa,Pa,Ma,tt,ja,ot,za,La,Ia,Te,rt,Da,be,Io;return m=new jt({}),B=new jt({}),De=new jt({}),qe=new Aa({props:{code:`from transformers import TrOCRProcessor, VisionEncoderDecoderModel
import requests
from PIL import Image

processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")

# load image from the IAM dataset
url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)

generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrOCRProcessor, VisionEncoderDecoderModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = TrOCRProcessor.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load image from the IAM dataset</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_ids = model.generate(pixel_values)

<span class="hljs-meta">&gt;&gt;&gt; </span>generated_text = processor.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`}}),Fe=new jt({}),Ve=new re({props:{name:"class transformers.TrOCRConfig",anchor:"transformers.TrOCRConfig",parameters:[{name:"vocab_size",val:" = 50265"},{name:"d_model",val:" = 1024"},{name:"decoder_layers",val:" = 12"},{name:"decoder_attention_heads",val:" = 16"},{name:"decoder_ffn_dim",val:" = 4096"},{name:"activation_function",val:" = 'gelu'"},{name:"max_position_embeddings",val:" = 512"},{name:"dropout",val:" = 0.1"},{name:"attention_dropout",val:" = 0.0"},{name:"activation_dropout",val:" = 0.0"},{name:"decoder_start_token_id",val:" = 2"},{name:"init_std",val:" = 0.02"},{name:"decoder_layerdrop",val:" = 0.0"},{name:"use_cache",val:" = True"},{name:"scale_embedding",val:" = False"},{name:"use_learned_position_embeddings",val:" = True"},{name:"layernorm_embedding",val:" = True"},{name:"pad_token_id",val:" = 1"},{name:"bos_token_id",val:" = 0"},{name:"eos_token_id",val:" = 2"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TrOCRConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 50265) &#x2014;
Vocabulary size of the TrOCR model. Defines the number of different tokens that can be represented by the
<code>inputs_ids</code> passed when calling <a href="/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRForCausalLM">TrOCRForCausalLM</a>.`,name:"vocab_size"},{anchor:"transformers.TrOCRConfig.d_model",description:`<strong>d_model</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
Dimensionality of the layers and the pooler layer.`,name:"d_model"},{anchor:"transformers.TrOCRConfig.decoder_layers",description:`<strong>decoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of decoder layers.`,name:"decoder_layers"},{anchor:"transformers.TrOCRConfig.decoder_attention_heads",description:`<strong>decoder_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
Number of attention heads for each attention layer in the Transformer decoder.`,name:"decoder_attention_heads"},{anchor:"transformers.TrOCRConfig.decoder_ffn_dim",description:`<strong>decoder_ffn_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 4096) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (often named feed-forward) layer in decoder.`,name:"decoder_ffn_dim"},{anchor:"transformers.TrOCRConfig.activation_function",description:`<strong>activation_function</strong> (<code>str</code> or <code>function</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the pooler. If string, <code>&quot;gelu&quot;</code>, <code>&quot;relu&quot;</code>,
<code>&quot;silu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"activation_function"},{anchor:"transformers.TrOCRConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 512) &#x2014;
The maximum sequence length that this model might ever be used with. Typically set this to something large
just in case (e.g., 512 or 1024 or 2048).`,name:"max_position_embeddings"},{anchor:"transformers.TrOCRConfig.dropout",description:`<strong>dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for all fully connected layers in the embeddings, and pooler.`,name:"dropout"},{anchor:"transformers.TrOCRConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.TrOCRConfig.activation_dropout",description:`<strong>activation_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for activations inside the fully connected layer.`,name:"activation_dropout"},{anchor:"transformers.TrOCRConfig.init_std",description:`<strong>init_std</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"init_std"},{anchor:"transformers.TrOCRConfig.decoder_layerdrop",description:`<strong>decoder_layerdrop</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The LayerDrop probability for the decoder. See the [LayerDrop paper](see <a href="https://arxiv.org/abs/1909.11556" rel="nofollow">https://arxiv.org/abs/1909.11556</a>)
for more details.`,name:"decoder_layerdrop"},{anchor:"transformers.TrOCRConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models).`,name:"use_cache"},{anchor:"transformers.TrOCRConfig.scale_embedding",description:`<strong>scale_embedding</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to scale the word embeddings by sqrt(d_model).`,name:"scale_embedding"},{anchor:"transformers.TrOCRConfig.use_learned_position_embeddings",description:`<strong>use_learned_position_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to use learned position embeddings. If not, sinusoidal position embeddings will be used.`,name:"use_learned_position_embeddings"},{anchor:"transformers.TrOCRConfig.layernorm_embedding",description:`<strong>layernorm_embedding</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to use a layernorm after the word + position embeddings.`,name:"layernorm_embedding"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/configuration_trocr.py#L31"}}),he=new ti({props:{anchor:"transformers.TrOCRConfig.example",$$slots:{default:[di]},$$scope:{ctx:W}}}),Se=new jt({}),We=new re({props:{name:"class transformers.TrOCRProcessor",anchor:"transformers.TrOCRProcessor",parameters:[{name:"image_processor",val:" = None"},{name:"tokenizer",val:" = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TrOCRProcessor.image_processor",description:`<strong>image_processor</strong> ([<code>ViTImageProcessor</code>/<code>DeiTImageProcessor</code>]) &#x2014;
An instance of [<code>ViTImageProcessor</code>/<code>DeiTImageProcessor</code>]. The image processor is a required input.`,name:"image_processor"},{anchor:"transformers.TrOCRProcessor.tokenizer",description:`<strong>tokenizer</strong> ([<code>RobertaTokenizer</code>/<code>XLMRobertaTokenizer</code>]) &#x2014;
An instance of [<code>RobertaTokenizer</code>/<code>XLMRobertaTokenizer</code>]. The tokenizer is a required input.`,name:"tokenizer"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/processing_trocr.py#L24"}}),He=new re({props:{name:"__call__",anchor:"transformers.TrOCRProcessor.__call__",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/processing_trocr.py#L61"}}),Ge=new re({props:{name:"from_pretrained",anchor:"transformers.TrOCRProcessor.from_pretrained",parameters:[{name:"pretrained_model_name_or_path",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TrOCRProcessor.from_pretrained.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
This can be either:</p>
<ul>
<li>a string, the <em>model id</em> of a pretrained feature_extractor hosted inside a model repo on
huggingface.co. Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or
namespaced under a user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li>
<li>a path to a <em>directory</em> containing a feature extractor file saved using the
<a href="/docs/transformers/v4.27.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.save_pretrained">save_pretrained()</a> method, e.g., <code>./my_model_directory/</code>.</li>
<li>a path or url to a saved feature extractor JSON <em>file</em>, e.g.,
<code>./my_model_directory/preprocessor_config.json</code>.
**kwargs &#x2014;
Additional keyword arguments passed along to both
<a href="/docs/transformers/v4.27.1/en/main_classes/feature_extractor#transformers.FeatureExtractionMixin.from_pretrained">from_pretrained()</a> and
<code>~tokenization_utils_base.PreTrainedTokenizer.from_pretrained</code>.</li>
</ul>`,name:"pretrained_model_name_or_path"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/processing_utils.py#L153"}}),fe=new ei({props:{$$slots:{default:[ci]},$$scope:{ctx:W}}}),Xe=new re({props:{name:"save_pretrained",anchor:"transformers.TrOCRProcessor.save_pretrained",parameters:[{name:"save_directory",val:""},{name:"push_to_hub",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TrOCRProcessor.save_pretrained.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Directory where the feature extractor JSON file and the tokenizer files will be saved (directory will
be created if it does not exist).`,name:"save_directory"},{anchor:"transformers.TrOCRProcessor.save_pretrained.push_to_hub",description:`<strong>push_to_hub</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
repository you want to push to with <code>repo_id</code> (will default to the name of <code>save_directory</code> in your
namespace).
kwargs &#x2014;
Additional key word arguments passed along to the <a href="/docs/transformers/v4.27.1/en/internal/image_processing_utils#transformers.ImageProcessingMixin.push_to_hub">push_to_hub()</a> method.`,name:"push_to_hub"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/processing_utils.py#L91"}}),ue=new ei({props:{$$slots:{default:[hi]},$$scope:{ctx:W}}}),Ze=new re({props:{name:"batch_decode",anchor:"transformers.TrOCRProcessor.batch_decode",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/processing_trocr.py#L94"}}),Ye=new re({props:{name:"decode",anchor:"transformers.TrOCRProcessor.decode",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/processing_trocr.py#L101"}}),Qe=new jt({}),et=new re({props:{name:"class transformers.TrOCRForCausalLM",anchor:"transformers.TrOCRForCausalLM",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.TrOCRForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRConfig">TrOCRConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/modeling_trocr.py#L785"}}),rt=new re({props:{name:"forward",anchor:"transformers.TrOCRForCausalLM.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_hidden_states",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"cross_attn_head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.TrOCRForCausalLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.TrOCRForCausalLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TrOCRForCausalLM.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong>  (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
if the model is configured as a decoder.`,name:"encoder_hidden_states"},{anchor:"transformers.TrOCRForCausalLM.forward.encoder_attention_mask",description:`<strong>encoder_attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used
in the cross-attention if the model is configured as a decoder. Mask values selected in <code>[0, 1]</code>:`,name:"encoder_attention_mask"},{anchor:"transformers.TrOCRForCausalLM.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.Tensor</code> of shape <code>(decoder_layers, decoder_attention_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.TrOCRForCausalLM.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(decoder_layers, decoder_attention_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the cross-attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"cross_attn_head_mask"},{anchor:"transformers.TrOCRForCausalLM.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) &#x2014;
Tuple of <code>tuple(torch.FloatTensor)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of
shape <code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>) and 2 additional tensors of
shape <code>(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)</code>. The two additional
tensors are only required when the model is used as a decoder in a Sequence to Sequence model.</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
cross-attention blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those
that don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of
all <code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.TrOCRForCausalLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the masked language modeling loss. Indices should either be in <code>[0, ..., config.vocab_size]</code> or -100 (see <code>input_ids</code> docstring). Tokens with indices set to <code>-100</code> are ignored
(masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>.`,name:"labels"},{anchor:"transformers.TrOCRForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding
(see <code>past_key_values</code>).</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>`,name:"use_cache"},{anchor:"transformers.TrOCRForCausalLM.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under
returned tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TrOCRForCausalLM.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors
for more detail.`,name:"output_hidden_states"},{anchor:"transformers.TrOCRForCausalLM.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.27.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/trocr/modeling_trocr.py#L818",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.27.1/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithCrossAttentions"
>transformers.modeling_outputs.CausalLMOutputWithCrossAttentions</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRConfig"
>TrOCRConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss (for next-token prediction).</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross attentions weights after the attention softmax, used to compute the weighted average in the
cross-attention heads.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> tuples of length <code>config.n_layers</code>, with each tuple containing the cached key,
value states of the self-attention and the cross-attention layers if model is used in encoder-decoder
setting. Only relevant if <code>config.is_decoder = True</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the attention blocks) that can be used (see
<code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.27.1/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithCrossAttentions"
>transformers.modeling_outputs.CausalLMOutputWithCrossAttentions</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),be=new ti({props:{anchor:"transformers.TrOCRForCausalLM.forward.example",$$slots:{default:[mi]},$$scope:{ctx:W}}}),{c(){f=a("meta"),R=c(),u=a("h1"),g=a("a"),T=a("span"),b(m.$$.fragment),_=c(),q=a("span"),I=r("TrOCR"),P=c(),j=a("h2"),M=a("a"),z=a("span"),b(B.$$.fragment),at=c(),se=a("span"),er=r("Overview"),fo=c(),H=a("p"),tr=r("The TrOCR model was proposed in "),$e=a("a"),or=r(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),rr=r(` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei. TrOCR consists of an image Transformer encoder and an autoregressive text Transformer decoder to
perform `),Re=a("a"),sr=r("optical character recognition (OCR)"),ar=r("."),uo=c(),nt=a("p"),nr=r("The abstract from the paper is the following:"),go=c(),it=a("p"),zt=a("em"),ir=r(`Text recognition is a long-standing research problem for document digitalization. Existing approaches for text recognition
are usually built based on CNN for image understanding and RNN for char-level text generation. In addition, another language
model is usually needed to improve the overall accuracy as a post-processing step. In this paper, we propose an end-to-end
text recognition approach with pre-trained image Transformer and text Transformer models, namely TrOCR, which leverages the
Transformer architecture for both image understanding and wordpiece-level text generation. The TrOCR model is simple but
effective, and can be pre-trained with large-scale synthetic data and fine-tuned with human-labeled datasets. Experiments
show that the TrOCR model outperforms the current state-of-the-art models on both printed and handwritten text recognition
tasks.`),_o=c(),ae=a("img"),vo=c(),ne=a("small"),lr=r("TrOCR architecture. Taken from the "),lt=a("a"),dr=r("original paper"),cr=r("."),To=c(),ie=a("p"),hr=r("Please refer to the "),Lt=a("code"),mr=r("VisionEncoderDecoder"),pr=r(" class on how to use this model."),bo=c(),G=a("p"),fr=r("This model was contributed by "),Ee=a("a"),ur=r("nielsr"),gr=r(`. The original code can be found
`),xe=a("a"),_r=r("here"),vr=r("."),Co=c(),dt=a("p"),Tr=r("Tips:"),wo=c(),X=a("ul"),Pe=a("li"),br=r("The quickest way to get started with TrOCR is by checking the "),Me=a("a"),Cr=r(`tutorial
notebooks`),wr=r(`, which show how to use the model
at inference time as well as fine-tuning on custom data.`),kr=c(),V=a("li"),Or=r(`TrOCR is pre-trained in 2 stages before being fine-tuned on downstream datasets. It achieves state-of-the-art results
on both printed (e.g. the `),je=a("a"),yr=r("SROIE dataset"),$r=r(" and handwritten (e.g. the "),ze=a("a"),Rr=r(`IAM
Handwriting dataset`),Er=r(` text recognition tasks. For more
information, see the `),Le=a("a"),xr=r("official models"),Pr=r("."),Mr=c(),Ie=a("li"),jr=r("TrOCR is always used within the "),ct=a("a"),zr=r("VisionEncoderDecoder"),Lr=r(" framework."),ko=c(),Y=a("h2"),le=a("a"),It=a("span"),b(De.$$.fragment),Ir=c(),Dt=a("span"),Dr=r("Inference"),Oo=c(),U=a("p"),qr=r("TrOCR\u2019s "),qt=a("code"),Ar=r("VisionEncoderDecoder"),Fr=r(` model accepts images as input and makes use of
`),ht=a("a"),Vr=r("generate()"),Nr=r(" to autoregressively generate text given the input image."),yo=c(),v=a("p"),Sr=r("The ["),At=a("code"),Wr=r("ViTImageProcessor"),Br=r("/"),Ft=a("code"),Hr=r("DeiTImageProcessor"),Gr=r(`] class is responsible for preprocessing the input image and
[`),Vt=a("code"),Xr=r("RobertaTokenizer"),Ur=r("/"),Nt=a("code"),Zr=r("XLMRobertaTokenizer"),Jr=r(`] decodes the generated target tokens to the target string. The
`),mt=a("a"),Yr=r("TrOCRProcessor"),Kr=r(" wraps ["),St=a("code"),Qr=r("ViTImageProcessor"),es=r("/"),Wt=a("code"),ts=r("DeiTImageProcessor"),os=r("] and ["),Bt=a("code"),rs=r("RobertaTokenizer"),ss=r("/"),Ht=a("code"),as=r("XLMRobertaTokenizer"),ns=r(`]
into a single instance to both extract the input features and decode the predicted token ids.`),$o=c(),pt=a("ul"),Gt=a("li"),is=r("Step-by-step Optical Character Recognition (OCR)"),Ro=c(),b(qe.$$.fragment),Eo=c(),de=a("p"),ls=r("See the "),Ae=a("a"),ds=r("model hub"),cs=r(" to look for TrOCR checkpoints."),xo=c(),K=a("h2"),ce=a("a"),Xt=a("span"),b(Fe.$$.fragment),hs=c(),Ut=a("span"),ms=r("TrOCRConfig"),Po=c(),A=a("div"),b(Ve.$$.fragment),ps=c(),Q=a("p"),fs=r("This is the configuration class to store the configuration of a "),ft=a("a"),us=r("TrOCRForCausalLM"),gs=r(`. It is used to instantiate an
TrOCR model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the TrOCR
`),Ne=a("a"),_s=r("microsoft/trocr-base-handwritten"),vs=r(" architecture."),Ts=c(),ee=a("p"),bs=r("Configuration objects inherit from "),ut=a("a"),Cs=r("PretrainedConfig"),ws=r(` and can be used to control the model outputs. Read the
documentation from `),gt=a("a"),ks=r("PretrainedConfig"),Os=r(" for more information."),ys=c(),b(he.$$.fragment),Mo=c(),te=a("h2"),me=a("a"),Zt=a("span"),b(Se.$$.fragment),$s=c(),Jt=a("span"),Rs=r("TrOCRProcessor"),jo=c(),$=a("div"),b(We.$$.fragment),Es=c(),Yt=a("p"),xs=r("Constructs a TrOCR processor which wraps a vision image processor and a TrOCR tokenizer into a single processor."),Ps=c(),x=a("p"),_t=a("a"),Ms=r("TrOCRProcessor"),js=r(" offers all the functionalities of ["),Kt=a("code"),zs=r("ViTImageProcessor"),Ls=r("/"),Qt=a("code"),Is=r("DeiTImageProcessor"),Ds=r(`] and
[`),eo=a("code"),qs=r("RobertaTokenizer"),As=r("/"),to=a("code"),Fs=r("XLMRobertaTokenizer"),Vs=r("]. See the "),Be=a("a"),oo=a("strong"),Ns=r("call"),Ss=r("()"),Ws=r(" and "),vt=a("a"),Bs=r("decode()"),Hs=r(` for
more information.`),Gs=c(),pe=a("div"),b(He.$$.fragment),Xs=c(),N=a("p"),Us=r(`When used in normal mode, this method forwards all its arguments to AutoImageProcessor\u2019s
`),ro=a("code"),Zs=r("__call__()"),Js=r(` and returns its output. If used in the context
`),so=a("code"),Ys=r("as_target_processor()"),Ks=r(` this method forwards all its arguments to TrOCRTokenizer\u2019s
`),ao=a("code"),Qs=r("~TrOCRTokenizer.__call__"),ea=r(". Please refer to the doctsring of the above two methods for more information."),ta=c(),Z=a("div"),b(Ge.$$.fragment),oa=c(),no=a("p"),ra=r("Instantiate a processor associated with a pretrained model."),sa=c(),b(fe.$$.fragment),aa=c(),J=a("div"),b(Xe.$$.fragment),na=c(),Ue=a("p"),ia=r(`Saves the attributes of this processor (feature extractor, tokenizer\u2026) in the specified directory so that it
can be reloaded using the `),Tt=a("a"),la=r("from_pretrained()"),da=r(" method."),ca=c(),b(ue.$$.fragment),ha=c(),ge=a("div"),b(Ze.$$.fragment),ma=c(),Je=a("p"),pa=r("This method forwards all its arguments to TrOCRTokenizer\u2019s "),bt=a("a"),fa=r("batch_decode()"),ua=r(`. Please refer
to the docstring of this method for more information.`),ga=c(),_e=a("div"),b(Ye.$$.fragment),_a=c(),Ke=a("p"),va=r("This method forwards all its arguments to TrOCRTokenizer\u2019s "),Ct=a("a"),Ta=r("decode()"),ba=r(`. Please refer to the
docstring of this method for more information.`),zo=c(),oe=a("h2"),ve=a("a"),io=a("span"),b(Qe.$$.fragment),Ca=c(),lo=a("span"),wa=r("TrOCRForCausalLM"),Lo=c(),F=a("div"),b(et.$$.fragment),ka=c(),S=a("p"),Oa=r("The TrOCR Decoder with a language modeling head. Can be used as the decoder part of "),wt=a("a"),ya=r("EncoderDecoderModel"),$a=r(" and "),co=a("code"),Ra=r("VisionEncoderDecoder"),Ea=r(`.
This model inherits from `),kt=a("a"),xa=r("PreTrainedModel"),Pa=r(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Ma=c(),tt=a("p"),ja=r("This model is also a PyTorch "),ot=a("a"),za=r("torch.nn.Module"),La=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ia=c(),Te=a("div"),b(rt.$$.fragment),Da=c(),b(be.$$.fragment),this.h()},l(t){const d=ni('[data-svelte="svelte-1phssyn"]',document.head);f=n(d,"META",{name:!0,content:!0}),d.forEach(o),R=h(t),u=n(t,"H1",{class:!0});var st=i(u);g=n(st,"A",{id:!0,class:!0,href:!0});var ho=i(g);T=n(ho,"SPAN",{});var mo=i(T);C(m.$$.fragment,mo),mo.forEach(o),ho.forEach(o),_=h(st),q=n(st,"SPAN",{});var po=i(q);I=s(po,"TrOCR"),po.forEach(o),st.forEach(o),P=h(t),j=n(t,"H2",{class:!0});var Do=i(j);M=n(Do,"A",{id:!0,class:!0,href:!0});var Va=i(M);z=n(Va,"SPAN",{});var Na=i(z);C(B.$$.fragment,Na),Na.forEach(o),Va.forEach(o),at=h(Do),se=n(Do,"SPAN",{});var Sa=i(se);er=s(Sa,"Overview"),Sa.forEach(o),Do.forEach(o),fo=h(t),H=n(t,"P",{});var Ot=i(H);tr=s(Ot,"The TrOCR model was proposed in "),$e=n(Ot,"A",{href:!0,rel:!0});var Wa=i($e);or=s(Wa,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),Wa.forEach(o),rr=s(Ot,` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei. TrOCR consists of an image Transformer encoder and an autoregressive text Transformer decoder to
perform `),Re=n(Ot,"A",{href:!0,rel:!0});var Ba=i(Re);sr=s(Ba,"optical character recognition (OCR)"),Ba.forEach(o),ar=s(Ot,"."),Ot.forEach(o),uo=h(t),nt=n(t,"P",{});var Ha=i(nt);nr=s(Ha,"The abstract from the paper is the following:"),Ha.forEach(o),go=h(t),it=n(t,"P",{});var Ga=i(it);zt=n(Ga,"EM",{});var Xa=i(zt);ir=s(Xa,`Text recognition is a long-standing research problem for document digitalization. Existing approaches for text recognition
are usually built based on CNN for image understanding and RNN for char-level text generation. In addition, another language
model is usually needed to improve the overall accuracy as a post-processing step. In this paper, we propose an end-to-end
text recognition approach with pre-trained image Transformer and text Transformer models, namely TrOCR, which leverages the
Transformer architecture for both image understanding and wordpiece-level text generation. The TrOCR model is simple but
effective, and can be pre-trained with large-scale synthetic data and fine-tuned with human-labeled datasets. Experiments
show that the TrOCR model outperforms the current state-of-the-art models on both printed and handwritten text recognition
tasks.`),Xa.forEach(o),Ga.forEach(o),_o=h(t),ae=n(t,"IMG",{src:!0,alt:!0,width:!0}),vo=h(t),ne=n(t,"SMALL",{});var qo=i(ne);lr=s(qo,"TrOCR architecture. Taken from the "),lt=n(qo,"A",{href:!0});var Ua=i(lt);dr=s(Ua,"original paper"),Ua.forEach(o),cr=s(qo,"."),qo.forEach(o),To=h(t),ie=n(t,"P",{});var Ao=i(ie);hr=s(Ao,"Please refer to the "),Lt=n(Ao,"CODE",{});var Za=i(Lt);mr=s(Za,"VisionEncoderDecoder"),Za.forEach(o),pr=s(Ao," class on how to use this model."),Ao.forEach(o),bo=h(t),G=n(t,"P",{});var yt=i(G);fr=s(yt,"This model was contributed by "),Ee=n(yt,"A",{href:!0,rel:!0});var Ja=i(Ee);ur=s(Ja,"nielsr"),Ja.forEach(o),gr=s(yt,`. The original code can be found
`),xe=n(yt,"A",{href:!0,rel:!0});var Ya=i(xe);_r=s(Ya,"here"),Ya.forEach(o),vr=s(yt,"."),yt.forEach(o),Co=h(t),dt=n(t,"P",{});var Ka=i(dt);Tr=s(Ka,"Tips:"),Ka.forEach(o),wo=h(t),X=n(t,"UL",{});var $t=i(X);Pe=n($t,"LI",{});var Fo=i(Pe);br=s(Fo,"The quickest way to get started with TrOCR is by checking the "),Me=n(Fo,"A",{href:!0,rel:!0});var Qa=i(Me);Cr=s(Qa,`tutorial
notebooks`),Qa.forEach(o),wr=s(Fo,`, which show how to use the model
at inference time as well as fine-tuning on custom data.`),Fo.forEach(o),kr=h($t),V=n($t,"LI",{});var Ce=i(V);Or=s(Ce,`TrOCR is pre-trained in 2 stages before being fine-tuned on downstream datasets. It achieves state-of-the-art results
on both printed (e.g. the `),je=n(Ce,"A",{href:!0,rel:!0});var en=i(je);yr=s(en,"SROIE dataset"),en.forEach(o),$r=s(Ce," and handwritten (e.g. the "),ze=n(Ce,"A",{href:!0,rel:!0});var tn=i(ze);Rr=s(tn,`IAM
Handwriting dataset`),tn.forEach(o),Er=s(Ce,` text recognition tasks. For more
information, see the `),Le=n(Ce,"A",{href:!0,rel:!0});var on=i(Le);xr=s(on,"official models"),on.forEach(o),Pr=s(Ce,"."),Ce.forEach(o),Mr=h($t),Ie=n($t,"LI",{});var Vo=i(Ie);jr=s(Vo,"TrOCR is always used within the "),ct=n(Vo,"A",{href:!0});var rn=i(ct);zr=s(rn,"VisionEncoderDecoder"),rn.forEach(o),Lr=s(Vo," framework."),Vo.forEach(o),$t.forEach(o),ko=h(t),Y=n(t,"H2",{class:!0});var No=i(Y);le=n(No,"A",{id:!0,class:!0,href:!0});var sn=i(le);It=n(sn,"SPAN",{});var an=i(It);C(De.$$.fragment,an),an.forEach(o),sn.forEach(o),Ir=h(No),Dt=n(No,"SPAN",{});var nn=i(Dt);Dr=s(nn,"Inference"),nn.forEach(o),No.forEach(o),Oo=h(t),U=n(t,"P",{});var Rt=i(U);qr=s(Rt,"TrOCR\u2019s "),qt=n(Rt,"CODE",{});var ln=i(qt);Ar=s(ln,"VisionEncoderDecoder"),ln.forEach(o),Fr=s(Rt,` model accepts images as input and makes use of
`),ht=n(Rt,"A",{href:!0});var dn=i(ht);Vr=s(dn,"generate()"),dn.forEach(o),Nr=s(Rt," to autoregressively generate text given the input image."),Rt.forEach(o),yo=h(t),v=n(t,"P",{});var E=i(v);Sr=s(E,"The ["),At=n(E,"CODE",{});var cn=i(At);Wr=s(cn,"ViTImageProcessor"),cn.forEach(o),Br=s(E,"/"),Ft=n(E,"CODE",{});var hn=i(Ft);Hr=s(hn,"DeiTImageProcessor"),hn.forEach(o),Gr=s(E,`] class is responsible for preprocessing the input image and
[`),Vt=n(E,"CODE",{});var mn=i(Vt);Xr=s(mn,"RobertaTokenizer"),mn.forEach(o),Ur=s(E,"/"),Nt=n(E,"CODE",{});var pn=i(Nt);Zr=s(pn,"XLMRobertaTokenizer"),pn.forEach(o),Jr=s(E,`] decodes the generated target tokens to the target string. The
`),mt=n(E,"A",{href:!0});var fn=i(mt);Yr=s(fn,"TrOCRProcessor"),fn.forEach(o),Kr=s(E," wraps ["),St=n(E,"CODE",{});var un=i(St);Qr=s(un,"ViTImageProcessor"),un.forEach(o),es=s(E,"/"),Wt=n(E,"CODE",{});var gn=i(Wt);ts=s(gn,"DeiTImageProcessor"),gn.forEach(o),os=s(E,"] and ["),Bt=n(E,"CODE",{});var _n=i(Bt);rs=s(_n,"RobertaTokenizer"),_n.forEach(o),ss=s(E,"/"),Ht=n(E,"CODE",{});var vn=i(Ht);as=s(vn,"XLMRobertaTokenizer"),vn.forEach(o),ns=s(E,`]
into a single instance to both extract the input features and decode the predicted token ids.`),E.forEach(o),$o=h(t),pt=n(t,"UL",{});var Tn=i(pt);Gt=n(Tn,"LI",{});var bn=i(Gt);is=s(bn,"Step-by-step Optical Character Recognition (OCR)"),bn.forEach(o),Tn.forEach(o),Ro=h(t),C(qe.$$.fragment,t),Eo=h(t),de=n(t,"P",{});var So=i(de);ls=s(So,"See the "),Ae=n(So,"A",{href:!0,rel:!0});var Cn=i(Ae);ds=s(Cn,"model hub"),Cn.forEach(o),cs=s(So," to look for TrOCR checkpoints."),So.forEach(o),xo=h(t),K=n(t,"H2",{class:!0});var Wo=i(K);ce=n(Wo,"A",{id:!0,class:!0,href:!0});var wn=i(ce);Xt=n(wn,"SPAN",{});var kn=i(Xt);C(Fe.$$.fragment,kn),kn.forEach(o),wn.forEach(o),hs=h(Wo),Ut=n(Wo,"SPAN",{});var On=i(Ut);ms=s(On,"TrOCRConfig"),On.forEach(o),Wo.forEach(o),Po=h(t),A=n(t,"DIV",{class:!0});var we=i(A);C(Ve.$$.fragment,we),ps=h(we),Q=n(we,"P",{});var Et=i(Q);fs=s(Et,"This is the configuration class to store the configuration of a "),ft=n(Et,"A",{href:!0});var yn=i(ft);us=s(yn,"TrOCRForCausalLM"),yn.forEach(o),gs=s(Et,`. It is used to instantiate an
TrOCR model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the TrOCR
`),Ne=n(Et,"A",{href:!0,rel:!0});var $n=i(Ne);_s=s($n,"microsoft/trocr-base-handwritten"),$n.forEach(o),vs=s(Et," architecture."),Et.forEach(o),Ts=h(we),ee=n(we,"P",{});var xt=i(ee);bs=s(xt,"Configuration objects inherit from "),ut=n(xt,"A",{href:!0});var Rn=i(ut);Cs=s(Rn,"PretrainedConfig"),Rn.forEach(o),ws=s(xt,` and can be used to control the model outputs. Read the
documentation from `),gt=n(xt,"A",{href:!0});var En=i(gt);ks=s(En,"PretrainedConfig"),En.forEach(o),Os=s(xt," for more information."),xt.forEach(o),ys=h(we),C(he.$$.fragment,we),we.forEach(o),Mo=h(t),te=n(t,"H2",{class:!0});var Bo=i(te);me=n(Bo,"A",{id:!0,class:!0,href:!0});var xn=i(me);Zt=n(xn,"SPAN",{});var Pn=i(Zt);C(Se.$$.fragment,Pn),Pn.forEach(o),xn.forEach(o),$s=h(Bo),Jt=n(Bo,"SPAN",{});var Mn=i(Jt);Rs=s(Mn,"TrOCRProcessor"),Mn.forEach(o),Bo.forEach(o),jo=h(t),$=n(t,"DIV",{class:!0});var L=i($);C(We.$$.fragment,L),Es=h(L),Yt=n(L,"P",{});var jn=i(Yt);xs=s(jn,"Constructs a TrOCR processor which wraps a vision image processor and a TrOCR tokenizer into a single processor."),jn.forEach(o),Ps=h(L),x=n(L,"P",{});var D=i(x);_t=n(D,"A",{href:!0});var zn=i(_t);Ms=s(zn,"TrOCRProcessor"),zn.forEach(o),js=s(D," offers all the functionalities of ["),Kt=n(D,"CODE",{});var Ln=i(Kt);zs=s(Ln,"ViTImageProcessor"),Ln.forEach(o),Ls=s(D,"/"),Qt=n(D,"CODE",{});var In=i(Qt);Is=s(In,"DeiTImageProcessor"),In.forEach(o),Ds=s(D,`] and
[`),eo=n(D,"CODE",{});var Dn=i(eo);qs=s(Dn,"RobertaTokenizer"),Dn.forEach(o),As=s(D,"/"),to=n(D,"CODE",{});var qn=i(to);Fs=s(qn,"XLMRobertaTokenizer"),qn.forEach(o),Vs=s(D,"]. See the "),Be=n(D,"A",{href:!0});var qa=i(Be);oo=n(qa,"STRONG",{});var An=i(oo);Ns=s(An,"call"),An.forEach(o),Ss=s(qa,"()"),qa.forEach(o),Ws=s(D," and "),vt=n(D,"A",{href:!0});var Fn=i(vt);Bs=s(Fn,"decode()"),Fn.forEach(o),Hs=s(D,` for
more information.`),D.forEach(o),Gs=h(L),pe=n(L,"DIV",{class:!0});var Ho=i(pe);C(He.$$.fragment,Ho),Xs=h(Ho),N=n(Ho,"P",{});var ke=i(N);Us=s(ke,`When used in normal mode, this method forwards all its arguments to AutoImageProcessor\u2019s
`),ro=n(ke,"CODE",{});var Vn=i(ro);Zs=s(Vn,"__call__()"),Vn.forEach(o),Js=s(ke,` and returns its output. If used in the context
`),so=n(ke,"CODE",{});var Nn=i(so);Ys=s(Nn,"as_target_processor()"),Nn.forEach(o),Ks=s(ke,` this method forwards all its arguments to TrOCRTokenizer\u2019s
`),ao=n(ke,"CODE",{});var Sn=i(ao);Qs=s(Sn,"~TrOCRTokenizer.__call__"),Sn.forEach(o),ea=s(ke,". Please refer to the doctsring of the above two methods for more information."),ke.forEach(o),Ho.forEach(o),ta=h(L),Z=n(L,"DIV",{class:!0});var Pt=i(Z);C(Ge.$$.fragment,Pt),oa=h(Pt),no=n(Pt,"P",{});var Wn=i(no);ra=s(Wn,"Instantiate a processor associated with a pretrained model."),Wn.forEach(o),sa=h(Pt),C(fe.$$.fragment,Pt),Pt.forEach(o),aa=h(L),J=n(L,"DIV",{class:!0});var Mt=i(J);C(Xe.$$.fragment,Mt),na=h(Mt),Ue=n(Mt,"P",{});var Go=i(Ue);ia=s(Go,`Saves the attributes of this processor (feature extractor, tokenizer\u2026) in the specified directory so that it
can be reloaded using the `),Tt=n(Go,"A",{href:!0});var Bn=i(Tt);la=s(Bn,"from_pretrained()"),Bn.forEach(o),da=s(Go," method."),Go.forEach(o),ca=h(Mt),C(ue.$$.fragment,Mt),Mt.forEach(o),ha=h(L),ge=n(L,"DIV",{class:!0});var Xo=i(ge);C(Ze.$$.fragment,Xo),ma=h(Xo),Je=n(Xo,"P",{});var Uo=i(Je);pa=s(Uo,"This method forwards all its arguments to TrOCRTokenizer\u2019s "),bt=n(Uo,"A",{href:!0});var Hn=i(bt);fa=s(Hn,"batch_decode()"),Hn.forEach(o),ua=s(Uo,`. Please refer
to the docstring of this method for more information.`),Uo.forEach(o),Xo.forEach(o),ga=h(L),_e=n(L,"DIV",{class:!0});var Zo=i(_e);C(Ye.$$.fragment,Zo),_a=h(Zo),Ke=n(Zo,"P",{});var Jo=i(Ke);va=s(Jo,"This method forwards all its arguments to TrOCRTokenizer\u2019s "),Ct=n(Jo,"A",{href:!0});var Gn=i(Ct);Ta=s(Gn,"decode()"),Gn.forEach(o),ba=s(Jo,`. Please refer to the
docstring of this method for more information.`),Jo.forEach(o),Zo.forEach(o),L.forEach(o),zo=h(t),oe=n(t,"H2",{class:!0});var Yo=i(oe);ve=n(Yo,"A",{id:!0,class:!0,href:!0});var Xn=i(ve);io=n(Xn,"SPAN",{});var Un=i(io);C(Qe.$$.fragment,Un),Un.forEach(o),Xn.forEach(o),Ca=h(Yo),lo=n(Yo,"SPAN",{});var Zn=i(lo);wa=s(Zn,"TrOCRForCausalLM"),Zn.forEach(o),Yo.forEach(o),Lo=h(t),F=n(t,"DIV",{class:!0});var Oe=i(F);C(et.$$.fragment,Oe),ka=h(Oe),S=n(Oe,"P",{});var ye=i(S);Oa=s(ye,"The TrOCR Decoder with a language modeling head. Can be used as the decoder part of "),wt=n(ye,"A",{href:!0});var Jn=i(wt);ya=s(Jn,"EncoderDecoderModel"),Jn.forEach(o),$a=s(ye," and "),co=n(ye,"CODE",{});var Yn=i(co);Ra=s(Yn,"VisionEncoderDecoder"),Yn.forEach(o),Ea=s(ye,`.
This model inherits from `),kt=n(ye,"A",{href:!0});var Kn=i(kt);xa=s(Kn,"PreTrainedModel"),Kn.forEach(o),Pa=s(ye,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),ye.forEach(o),Ma=h(Oe),tt=n(Oe,"P",{});var Ko=i(tt);ja=s(Ko,"This model is also a PyTorch "),ot=n(Ko,"A",{href:!0,rel:!0});var Qn=i(ot);za=s(Qn,"torch.nn.Module"),Qn.forEach(o),La=s(Ko,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ko.forEach(o),Ia=h(Oe),Te=n(Oe,"DIV",{class:!0});var Qo=i(Te);C(rt.$$.fragment,Qo),Da=h(Qo),C(be.$$.fragment,Qo),Qo.forEach(o),Oe.forEach(o),this.h()},h(){l(f,"name","hf:doc:metadata"),l(f,"content",JSON.stringify(fi)),l(g,"id","trocr"),l(g,"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"),l(g,"href","#trocr"),l(u,"class","relative group"),l(M,"id","overview"),l(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"),l(M,"href","#overview"),l(j,"class","relative group"),l($e,"href","https://arxiv.org/abs/2109.10282"),l($e,"rel","nofollow"),l(Re,"href","https://en.wikipedia.org/wiki/Optical_character_recognition"),l(Re,"rel","nofollow"),ii(ae.src,Fa="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/trocr_architecture.jpg")||l(ae,"src",Fa),l(ae,"alt","drawing"),l(ae,"width","600"),l(lt,"href","https://arxiv.org/abs/2109.10282"),l(Ee,"href","https://huggingface.co/nielsr"),l(Ee,"rel","nofollow"),l(xe,"href","https://github.com/microsoft/unilm/tree/6f60612e7cc86a2a1ae85c47231507a587ab4e01/trocr"),l(xe,"rel","nofollow"),l(Me,"href","https://github.com/NielsRogge/Transformers-Tutorials/tree/master/TrOCR"),l(Me,"rel","nofollow"),l(je,"href","https://paperswithcode.com/dataset/sroie"),l(je,"rel","nofollow"),l(ze,"href","https://fki.tic.heia-fr.ch/databases/iam-handwriting-database%3E"),l(ze,"rel","nofollow"),l(Le,"href","https://huggingface.co/models?other=trocr%3E"),l(Le,"rel","nofollow"),l(ct,"href","vision-encoder-decoder"),l(le,"id","inference"),l(le,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(le,"href","#inference"),l(Y,"class","relative group"),l(ht,"href","/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate"),l(mt,"href","/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRProcessor"),l(Ae,"href","https://huggingface.co/models?filter=trocr"),l(Ae,"rel","nofollow"),l(ce,"id","transformers.TrOCRConfig"),l(ce,"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"),l(ce,"href","#transformers.TrOCRConfig"),l(K,"class","relative group"),l(ft,"href","/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRForCausalLM"),l(Ne,"href","https://huggingface.co/microsoft/trocr-base-handwritten"),l(Ne,"rel","nofollow"),l(ut,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),l(gt,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),l(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(me,"id","transformers.TrOCRProcessor"),l(me,"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"),l(me,"href","#transformers.TrOCRProcessor"),l(te,"class","relative group"),l(_t,"href","/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRProcessor"),l(Be,"href","/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRProcessor.__call__"),l(vt,"href","/docs/transformers/v4.27.1/en/model_doc/trocr#transformers.TrOCRProcessor.decode"),l(pe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Tt,"href","/docs/transformers/v4.27.1/en/main_classes/processors#transformers.ProcessorMixin.from_pretrained"),l(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(bt,"href","/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.batch_decode"),l(ge,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Ct,"href","/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.decode"),l(_e,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ve,"id","transformers.TrOCRForCausalLM"),l(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"),l(ve,"href","#transformers.TrOCRForCausalLM"),l(oe,"class","relative group"),l(wt,"href","/docs/transformers/v4.27.1/en/model_doc/encoder-decoder#transformers.EncoderDecoderModel"),l(kt,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),l(ot,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(ot,"rel","nofollow"),l(Te,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,d){e(document.head,f),p(t,R,d),p(t,u,d),e(u,g),e(g,T),w(m,T,null),e(u,_),e(u,q),e(q,I),p(t,P,d),p(t,j,d),e(j,M),e(M,z),w(B,z,null),e(j,at),e(j,se),e(se,er),p(t,fo,d),p(t,H,d),e(H,tr),e(H,$e),e($e,or),e(H,rr),e(H,Re),e(Re,sr),e(H,ar),p(t,uo,d),p(t,nt,d),e(nt,nr),p(t,go,d),p(t,it,d),e(it,zt),e(zt,ir),p(t,_o,d),p(t,ae,d),p(t,vo,d),p(t,ne,d),e(ne,lr),e(ne,lt),e(lt,dr),e(ne,cr),p(t,To,d),p(t,ie,d),e(ie,hr),e(ie,Lt),e(Lt,mr),e(ie,pr),p(t,bo,d),p(t,G,d),e(G,fr),e(G,Ee),e(Ee,ur),e(G,gr),e(G,xe),e(xe,_r),e(G,vr),p(t,Co,d),p(t,dt,d),e(dt,Tr),p(t,wo,d),p(t,X,d),e(X,Pe),e(Pe,br),e(Pe,Me),e(Me,Cr),e(Pe,wr),e(X,kr),e(X,V),e(V,Or),e(V,je),e(je,yr),e(V,$r),e(V,ze),e(ze,Rr),e(V,Er),e(V,Le),e(Le,xr),e(V,Pr),e(X,Mr),e(X,Ie),e(Ie,jr),e(Ie,ct),e(ct,zr),e(Ie,Lr),p(t,ko,d),p(t,Y,d),e(Y,le),e(le,It),w(De,It,null),e(Y,Ir),e(Y,Dt),e(Dt,Dr),p(t,Oo,d),p(t,U,d),e(U,qr),e(U,qt),e(qt,Ar),e(U,Fr),e(U,ht),e(ht,Vr),e(U,Nr),p(t,yo,d),p(t,v,d),e(v,Sr),e(v,At),e(At,Wr),e(v,Br),e(v,Ft),e(Ft,Hr),e(v,Gr),e(v,Vt),e(Vt,Xr),e(v,Ur),e(v,Nt),e(Nt,Zr),e(v,Jr),e(v,mt),e(mt,Yr),e(v,Kr),e(v,St),e(St,Qr),e(v,es),e(v,Wt),e(Wt,ts),e(v,os),e(v,Bt),e(Bt,rs),e(v,ss),e(v,Ht),e(Ht,as),e(v,ns),p(t,$o,d),p(t,pt,d),e(pt,Gt),e(Gt,is),p(t,Ro,d),w(qe,t,d),p(t,Eo,d),p(t,de,d),e(de,ls),e(de,Ae),e(Ae,ds),e(de,cs),p(t,xo,d),p(t,K,d),e(K,ce),e(ce,Xt),w(Fe,Xt,null),e(K,hs),e(K,Ut),e(Ut,ms),p(t,Po,d),p(t,A,d),w(Ve,A,null),e(A,ps),e(A,Q),e(Q,fs),e(Q,ft),e(ft,us),e(Q,gs),e(Q,Ne),e(Ne,_s),e(Q,vs),e(A,Ts),e(A,ee),e(ee,bs),e(ee,ut),e(ut,Cs),e(ee,ws),e(ee,gt),e(gt,ks),e(ee,Os),e(A,ys),w(he,A,null),p(t,Mo,d),p(t,te,d),e(te,me),e(me,Zt),w(Se,Zt,null),e(te,$s),e(te,Jt),e(Jt,Rs),p(t,jo,d),p(t,$,d),w(We,$,null),e($,Es),e($,Yt),e(Yt,xs),e($,Ps),e($,x),e(x,_t),e(_t,Ms),e(x,js),e(x,Kt),e(Kt,zs),e(x,Ls),e(x,Qt),e(Qt,Is),e(x,Ds),e(x,eo),e(eo,qs),e(x,As),e(x,to),e(to,Fs),e(x,Vs),e(x,Be),e(Be,oo),e(oo,Ns),e(Be,Ss),e(x,Ws),e(x,vt),e(vt,Bs),e(x,Hs),e($,Gs),e($,pe),w(He,pe,null),e(pe,Xs),e(pe,N),e(N,Us),e(N,ro),e(ro,Zs),e(N,Js),e(N,so),e(so,Ys),e(N,Ks),e(N,ao),e(ao,Qs),e(N,ea),e($,ta),e($,Z),w(Ge,Z,null),e(Z,oa),e(Z,no),e(no,ra),e(Z,sa),w(fe,Z,null),e($,aa),e($,J),w(Xe,J,null),e(J,na),e(J,Ue),e(Ue,ia),e(Ue,Tt),e(Tt,la),e(Ue,da),e(J,ca),w(ue,J,null),e($,ha),e($,ge),w(Ze,ge,null),e(ge,ma),e(ge,Je),e(Je,pa),e(Je,bt),e(bt,fa),e(Je,ua),e($,ga),e($,_e),w(Ye,_e,null),e(_e,_a),e(_e,Ke),e(Ke,va),e(Ke,Ct),e(Ct,Ta),e(Ke,ba),p(t,zo,d),p(t,oe,d),e(oe,ve),e(ve,io),w(Qe,io,null),e(oe,Ca),e(oe,lo),e(lo,wa),p(t,Lo,d),p(t,F,d),w(et,F,null),e(F,ka),e(F,S),e(S,Oa),e(S,wt),e(wt,ya),e(S,$a),e(S,co),e(co,Ra),e(S,Ea),e(S,kt),e(kt,xa),e(S,Pa),e(F,Ma),e(F,tt),e(tt,ja),e(tt,ot),e(ot,za),e(tt,La),e(F,Ia),e(F,Te),w(rt,Te,null),e(Te,Da),w(be,Te,null),Io=!0},p(t,[d]){const st={};d&2&&(st.$$scope={dirty:d,ctx:t}),he.$set(st);const ho={};d&2&&(ho.$$scope={dirty:d,ctx:t}),fe.$set(ho);const mo={};d&2&&(mo.$$scope={dirty:d,ctx:t}),ue.$set(mo);const po={};d&2&&(po.$$scope={dirty:d,ctx:t}),be.$set(po)},i(t){Io||(k(m.$$.fragment,t),k(B.$$.fragment,t),k(De.$$.fragment,t),k(qe.$$.fragment,t),k(Fe.$$.fragment,t),k(Ve.$$.fragment,t),k(he.$$.fragment,t),k(Se.$$.fragment,t),k(We.$$.fragment,t),k(He.$$.fragment,t),k(Ge.$$.fragment,t),k(fe.$$.fragment,t),k(Xe.$$.fragment,t),k(ue.$$.fragment,t),k(Ze.$$.fragment,t),k(Ye.$$.fragment,t),k(Qe.$$.fragment,t),k(et.$$.fragment,t),k(rt.$$.fragment,t),k(be.$$.fragment,t),Io=!0)},o(t){O(m.$$.fragment,t),O(B.$$.fragment,t),O(De.$$.fragment,t),O(qe.$$.fragment,t),O(Fe.$$.fragment,t),O(Ve.$$.fragment,t),O(he.$$.fragment,t),O(Se.$$.fragment,t),O(We.$$.fragment,t),O(He.$$.fragment,t),O(Ge.$$.fragment,t),O(fe.$$.fragment,t),O(Xe.$$.fragment,t),O(ue.$$.fragment,t),O(Ze.$$.fragment,t),O(Ye.$$.fragment,t),O(Qe.$$.fragment,t),O(et.$$.fragment,t),O(rt.$$.fragment,t),O(be.$$.fragment,t),Io=!1},d(t){o(f),t&&o(R),t&&o(u),y(m),t&&o(P),t&&o(j),y(B),t&&o(fo),t&&o(H),t&&o(uo),t&&o(nt),t&&o(go),t&&o(it),t&&o(_o),t&&o(ae),t&&o(vo),t&&o(ne),t&&o(To),t&&o(ie),t&&o(bo),t&&o(G),t&&o(Co),t&&o(dt),t&&o(wo),t&&o(X),t&&o(ko),t&&o(Y),y(De),t&&o(Oo),t&&o(U),t&&o(yo),t&&o(v),t&&o($o),t&&o(pt),t&&o(Ro),y(qe,t),t&&o(Eo),t&&o(de),t&&o(xo),t&&o(K),y(Fe),t&&o(Po),t&&o(A),y(Ve),y(he),t&&o(Mo),t&&o(te),y(Se),t&&o(jo),t&&o($),y(We),y(He),y(Ge),y(fe),y(Xe),y(ue),y(Ze),y(Ye),t&&o(zo),t&&o(oe),y(Qe),t&&o(Lo),t&&o(F),y(et),y(rt),y(be)}}}const fi={local:"trocr",sections:[{local:"overview",title:"Overview"},{local:"inference",title:"Inference"},{local:"transformers.TrOCRConfig",title:"TrOCRConfig"},{local:"transformers.TrOCRProcessor",title:"TrOCRProcessor"},{local:"transformers.TrOCRForCausalLM",title:"TrOCRForCausalLM"}],title:"TrOCR"};function ui(W){return li(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class wi extends ri{constructor(f){super();si(this,f,ui,pi,ai,{})}}export{wi as default,fi as metadata};
