import{s as Bl,o as Wl,n as Nl}from"../chunks/scheduler.9bc65507.js";import{S as Vl,i as El,g as p,s as l,u as o,A as Fl,h as i,f as n,c as e,j as x,v as c,y as r,k as M,o as u,a as t,w as h,d as j,t as d,x as m}from"../chunks/index.78c82d43.js";import{T as Ql}from"../chunks/Tip.87d55b76.js";import{I as E}from"../chunks/IconCopyLink.bedaa44d.js";import{C as g}from"../chunks/CodeBlock.48618ec2.js";import{D as zl}from"../chunks/DocNotebookDropdown.40f7599b.js";function ql(Aa){let w,F="The task illustrated in this tutorial is supported by the following model architectures:",b,f,J='<a href="../model_doc/layoutlm">LayoutLM</a>, <a href="../model_doc/layoutlmv2">LayoutLMv2</a>, <a href="../model_doc/layoutlmv3">LayoutLMv3</a>';return{c(){w=p("p"),w.textContent=F,b=l(),f=p("p"),f.innerHTML=J},l(y){w=i(y,"P",{"data-svelte-h":!0}),r(w)!=="svelte-6l5sa6"&&(w.textContent=F),b=e(y),f=i(y,"P",{"data-svelte-h":!0}),r(f)!=="svelte-4nltzx"&&(f.innerHTML=J)},m(y,U){t(y,w,U),t(y,b,U),t(y,f,U)},p:Nl,d(y){y&&(n(w),n(b),n(f))}}}function Yl(Aa){let w,F,b,f,J,y,U,Q,ut,ua,Ut="Document Question Answering",Ra,z,Xa,q,Tt=`Document Question Answering, also referred to as Document Visual Question Answering, is a task that involves providing
answers to questions posed about document images. The input to models supporting this task is typically a combination of an image and
a question, and the output is an answer expressed in natural language. These models utilize multiple modalities, including
text, the positions of words (bounding boxes), and the image itself.`,$a,Y,Ct="This guide illustrates how to:",Ga,H,It='<li>Fine-tune <a href="../model_doc/layoutlmv2">LayoutLMv2</a> on the <a href="https://huggingface.co/datasets/nielsr/docvqa_1200_examples_donut" rel="nofollow">DocVQA dataset</a>.</li> <li>Use your fine-tuned model for inference.</li>',Ba,A,Wa,S,vt=`LayoutLMv2 solves the document question-answering task by adding a question-answering head on top of the final hidden
states of the tokens, to predict the positions of the start and end tokens of the
answer. In other words, the problem is treated as extractive question answering: given the context, extract which piece
of information answers the question. The context comes from the output of an OCR engine, here it is Google’s Tesseract.`,Na,L,_t="Before you begin, make sure you have all the necessary libraries installed. LayoutLMv2 depends on detectron2, torchvision and tesseract.",Va,P,Ea,D,Fa,K,Qa,O,kt="Once you have installed all of the dependencies, restart your runtime.",za,ss,Zt=`We encourage you to share your model with the community. Log in to your Hugging Face account to upload it to the 🤗 Hub.
When prompted, enter your token to log in:`,qa,as,Ya,ns,At="Let’s define some global variables.",Ha,ts,Sa,T,R,Ua,ls,gt,ga,Rt="Load the data",La,es,Xt=`In this guide we use a small sample of preprocessed DocVQA that you can find on 🤗 Hub. If you’d like to use the full
DocVQA dataset, you can register and download it on <a href="https://rrc.cvc.uab.es/?ch=17" rel="nofollow">DocVQA homepage</a>. If you do so, to
proceed with this guide check out <a href="https://huggingface.co/docs/datasets/loading#local-and-remote-files" rel="nofollow">how to load files into a 🤗 dataset</a>.`,Pa,ps,Da,is,$t=`As you can see, the dataset is split into train and test sets already. Take a look at a random example to familiarize
yourself with the features.`,Ka,rs,Oa,os,Gt="Here’s what the individual fields represent:",sn,cs,Bt="<li><code>id</code>: the example’s id</li> <li><code>image</code>: a PIL.Image.Image object containing the document image</li> <li><code>query</code>: the question string - natural language asked question, in several languages</li> <li><code>answers</code>: a list of correct answers provided by human annotators</li> <li><code>words</code> and <code>bounding_boxes</code>: the results of OCR, which we will not use here</li> <li><code>answer</code>: an answer matched by a different model which we will not use here</li>",an,hs,Wt=`Let’s leave only English questions, and drop the <code>answer</code> feature which appears to contain predictions by another model.
We’ll also take the first of the answers from the set provided by the annotators. Alternatively, you can randomly sample it.`,nn,js,tn,ds,Nt=`Note that the LayoutLMv2 checkpoint that we use in this guide has been trained with <code>max_position_embeddings = 512</code> (you can
find this information in the <a href="https://huggingface.co/microsoft/layoutlmv2-base-uncased/blob/main/config.json#L18" rel="nofollow">checkpoint’s <code>config.json</code> file</a>).
We can truncate the examples but to avoid the situation where the answer might be at the end of a large document and end up truncated,
here we’ll remove the few examples where the embedding is likely to end up longer than 512.
If most of the documents in your dataset are long, you can implement a sliding window strategy - check out <a href="https://github.com/huggingface/notebooks/blob/main/examples/question_answering.ipynb" rel="nofollow">this notebook</a> for details.`,ln,ms,en,Ms,Vt=`At this point let’s also remove the OCR features from this dataset. These are a result of OCR for fine-tuning a different
model. They would still require some processing if we wanted to use them, as they do not match the input requirements
of the model we use in this guide. Instead, we can use the <a href="/docs/transformers/v4.33.3/en/model_doc/layoutlmv2#transformers.LayoutLMv2Processor">LayoutLMv2Processor</a> on the original data for both OCR and
tokenization. This way we’ll get the inputs that match model’s expected input. If you want to process images manually,
check out the <a href="../model_doc/layoutlmv2"><code>LayoutLMv2</code> model documentation</a> to learn what input format the model expects.`,pn,us,rn,gs,Et="Finally, the data exploration won’t be complete if we don’t peek at an image example.",on,xs,cn,X,Ft='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/docvqa_example.jpg" alt="DocVQA Image Example"/>',hn,C,$,Ta,ys,xt,xa,Qt="Preprocess the data",jn,ws,zt=`The Document Question Answering task is a multimodal task, and you need to make sure that the inputs from each modality
are preprocessed according to the model’s expectations. Let’s start by loading the <a href="/docs/transformers/v4.33.3/en/model_doc/layoutlmv2#transformers.LayoutLMv2Processor">LayoutLMv2Processor</a>, which internally combines an image processor that can handle image data and a tokenizer that can encode text data.`,dn,fs,mn,I,G,Ca,Js,yt,ya,qt="Preprocessing document images",Mn,bs,Yt=`First, let’s prepare the document images for the model with the help of the <code>image_processor</code> from the processor.
By default, image processor resizes the images to 224x224, makes sure they have the correct order of color channels,
applies OCR with tesseract to get words and normalized bounding boxes. In this tutorial, all of these defaults are exactly what we need.
Write a function that applies the default image processing to a batch of images and returns the results of OCR.`,un,Us,gn,Ts,Ht='To apply this preprocessing to the entire dataset in a fast way, use <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.map" rel="nofollow">map</a>.',xn,Cs,yn,v,B,Ia,Is,wt,wa,St="Preprocessing text data",wn,vs,Lt=`Once we have applied OCR to the images, we need to encode the text part of the dataset to prepare it for the model.
This involves converting the words and boxes that we got in the previous step to token-level <code>input_ids</code>, <code>attention_mask</code>,
<code>token_type_ids</code> and <code>bbox</code>. For preprocessing text, we’ll need the <code>tokenizer</code> from the processor.`,fn,_s,Jn,ks,Pt=`On top of the preprocessing mentioned above, we also need to add the labels for the model. For <code>xxxForQuestionAnswering</code> models
in 🤗 Transformers, the labels consist of the <code>start_positions</code> and <code>end_positions</code>, indicating which token is at the
start and which token is at the end of the answer.`,bn,Zs,Dt="Let’s start with that. Define a helper function that can find a sublist (the answer split into words) in a larger list (the words list).",Un,As,Kt=`This function will take two lists as input, <code>words_list</code> and <code>answer_list</code>. It will then iterate over the <code>words_list</code> and check
if the current word in the <code>words_list</code> (words_list[i]) is equal to the first word of answer_list (answer_list[0]) and if
the sublist of <code>words_list</code> starting from the current word and of the same length as <code>answer_list</code> is equal <code>to answer_list</code>.
If this condition is true, it means that a match has been found, and the function will record the match, its starting index (idx),
and its ending index (idx + len(answer_list) - 1). If more than one match was found, the function will return only the first one.
If no match is found, the function returns (<code>None</code>, 0, and 0).`,Tn,Rs,Cn,Xs,Ot="To illustrate how this function finds the position of the answer, let’s use it on an example:",In,$s,vn,Gs,sl="Once examples are encoded, however, they will look like this:",_n,Bs,kn,Ws,al="We’ll need to find the position of the answer in the encoded input.",Zn,Ns,nl=`<li><code>token_type_ids</code> tells us which tokens are part of the question, and which ones are part of the document’s words.</li> <li><code>tokenizer.cls_token_id</code> will help find the special token at the beginning of the input.</li> <li><code>word_ids</code> will help match the answer found in the original <code>words</code> to the same answer in the full encoded input and determine
the start/end position of the answer in the encoded input.</li>`,An,Vs,tl="With that in mind, let’s create a function to encode a batch of examples in the dataset:",Rn,Es,Xn,Fs,ll="Now that we have this preprocessing function, we can encode the entire dataset:",$n,Qs,Gn,zs,el="Let’s check what the features of the encoded dataset look like:",Bn,qs,Wn,_,W,va,Ys,ft,fa,pl="Evaluation",Nn,Hs,il=`Evaluation for document question answering requires a significant amount of postprocessing. To avoid taking up too much
of your time, this guide skips the evaluation step. The <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> still calculates the evaluation loss during training so
you’re not completely in the dark about your model’s performance. Extractive question answering is typically evaluated using F1/exact match.
If you’d like to implement it yourself, check out the <a href="https://huggingface.co/course/chapter7/7?fw=pt#postprocessing" rel="nofollow">Question Answering chapter</a>
of the Hugging Face course for inspiration.`,Vn,k,N,_a,Ss,Jt,Ja,rl="Train",En,Ls,ol=`Congratulations! You’ve successfully navigated the toughest part of this guide and now you are ready to train your own model.
Training involves the following steps:`,Fn,Ps,cl='<li>Load the model with <a href="/docs/transformers/v4.33.3/en/model_doc/auto#transformers.AutoModelForDocumentQuestionAnswering">AutoModelForDocumentQuestionAnswering</a> using the same checkpoint as in the preprocessing.</li> <li>Define your training hyperparameters in <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>.</li> <li>Define a function to batch examples together, here the <a href="/docs/transformers/v4.33.3/en/main_classes/data_collator#transformers.DefaultDataCollator">DefaultDataCollator</a> will do just fine</li> <li>Pass the training arguments to <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with the model, dataset, and data collator.</li> <li>Call <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.train">train()</a> to finetune your model.</li>',Qn,Ds,zn,Ks,hl=`In the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> use <code>output_dir</code> to specify where to save your model, and configure hyperparameters as you see fit.
If you wish to share your model with the community, set <code>push_to_hub</code> to <code>True</code> (you must be signed in to Hugging Face to upload your model).
In this case the <code>output_dir</code> will also be the name of the repo where your model checkpoint will be pushed.`,qn,Os,Yn,sa,jl="Define a simple data collator to batch examples together.",Hn,aa,Sn,na,dl='Finally, bring everything together, and call <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.train">train()</a>:',Ln,ta,Pn,la,ml="To add the final model to 🤗 Hub, create a model card and call <code>push_to_hub</code>:",Dn,ea,Kn,Z,V,ka,pa,bt,ba,Ml="Inference",On,ia,ul=`Now that you have finetuned a LayoutLMv2 model, and uploaded it to the 🤗 Hub, you can use it for inference. The simplest
way to try out your finetuned model for inference is to use it in a <a href="/docs/transformers/v4.33.3/en/main_classes/pipelines#transformers.Pipeline">Pipeline</a>.`,st,ra,gl="Let’s take an example:",at,oa,nt,ca,xl=`Next, instantiate a pipeline for
document question answering with your model, and pass the image + question combination to it.`,tt,ha,lt,ja,yl="You can also manually replicate the results of the pipeline if you’d like:",et,da,wl=`<li>Take an image and a question, prepare them for the model using the processor from your model.</li> <li>Forward the result or preprocessing through the model.</li> <li>The model returns <code>start_logits</code> and <code>end_logits</code>, which indicate which token is at the start of the answer and
which token is at the end of the answer. Both have shape (batch_size, sequence_length).</li> <li>Take an argmax on the last dimension of both the <code>start_logits</code> and <code>end_logits</code> to get the predicted <code>start_idx</code> and <code>end_idx</code>.</li> <li>Decode the answer with the tokenizer.</li>`,pt,ma,it,Za,rt;return Q=new E({}),z=new zl({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/document_question_answering.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/document_question_answering.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/document_question_answering.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/document_question_answering.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/document_question_answering.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/document_question_answering.ipynb"}]}}),A=new Ql({props:{$$slots:{default:[ql]},$$scope:{ctx:Aa}}}),P=new g({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwdHJhbnNmb3JtZXJzJTIwZGF0YXNldHM=",highlighted:"pip install -q transformers datasets"}}),D=new g({props:{code:"cGlwJTIwaW5zdGFsbCUyMCdnaXQlMkJodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZmYWNlYm9va3Jlc2VhcmNoJTJGZGV0ZWN0cm9uMi5naXQnJTBBcGlwJTIwaW5zdGFsbCUyMHRvcmNodmlzaW9u",highlighted:`pip install <span class="hljs-string">&#x27;git+https://github.com/facebookresearch/detectron2.git&#x27;</span>
pip install torchvision`}}),K=new g({props:{code:"c3VkbyUyMGFwdCUyMGluc3RhbGwlMjB0ZXNzZXJhY3Qtb2NyJTBBcGlwJTIwaW5zdGFsbCUyMC1xJTIwcHl0ZXNzZXJhY3Q=",highlighted:`sudo apt install tesseract-ocr
pip install -q pytesseract`}}),as=new g({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),ts=new g({props:{code:"bW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMm1pY3Jvc29mdCUyRmxheW91dGxtdjItYmFzZS11bmNhc2VkJTIyJTBBYmF0Y2hfc2l6ZSUyMCUzRCUyMDQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>model_checkpoint = <span class="hljs-string">&quot;microsoft/layoutlmv2-base-uncased&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>batch_size = <span class="hljs-number">4</span>`}}),ls=new E({}),ps=new g({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJuaWVsc3IlMkZkb2N2cWFfMTIwMF9leGFtcGxlcyUyMiklMEFkYXRhc2V0",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;nielsr/docvqa_1200_examples&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset
DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;query&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>, <span class="hljs-string">&#x27;words&#x27;</span>, <span class="hljs-string">&#x27;bounding_boxes&#x27;</span>, <span class="hljs-string">&#x27;answer&#x27;</span>],
        num_rows: <span class="hljs-number">1000</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;query&#x27;</span>, <span class="hljs-string">&#x27;answers&#x27;</span>, <span class="hljs-string">&#x27;words&#x27;</span>, <span class="hljs-string">&#x27;bounding_boxes&#x27;</span>, <span class="hljs-string">&#x27;answer&#x27;</span>],
        num_rows: <span class="hljs-number">200</span>
    })
})`}}),rs=new g({props:{code:"ZGF0YXNldCU1QiUyMnRyYWluJTIyJTVELmZlYXR1cmVz",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset[<span class="hljs-string">&quot;train&quot;</span>].features'}}),js=new g({props:{code:"dXBkYXRlZF9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldC5tYXAobGFtYmRhJTIwZXhhbXBsZSUzQSUyMCU3QiUyMnF1ZXN0aW9uJTIyJTNBJTIwZXhhbXBsZSU1QiUyMnF1ZXJ5JTIyJTVEJTVCJTIyZW4lMjIlNUQlN0QlMkMlMjByZW1vdmVfY29sdW1ucyUzRCU1QiUyMnF1ZXJ5JTIyJTVEKSUwQXVwZGF0ZWRfZGF0YXNldCUyMCUzRCUyMHVwZGF0ZWRfZGF0YXNldC5tYXAoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIwZXhhbXBsZSUzQSUyMCU3QiUyMmFuc3dlciUyMiUzQSUyMGV4YW1wbGUlNUIlMjJhbnN3ZXJzJTIyJTVEJTVCMCU1RCU3RCUyQyUyMHJlbW92ZV9jb2x1bW5zJTNEJTVCJTIyYW5zd2VyJTIyJTJDJTIwJTIyYW5zd2VycyUyMiU1RCUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset = dataset.<span class="hljs-built_in">map</span>(<span class="hljs-keyword">lambda</span> example: {<span class="hljs-string">&quot;question&quot;</span>: example[<span class="hljs-string">&quot;query&quot;</span>][<span class="hljs-string">&quot;en&quot;</span>]}, remove_columns=[<span class="hljs-string">&quot;query&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset = updated_dataset.<span class="hljs-built_in">map</span>(
<span class="hljs-meta">... </span>    <span class="hljs-keyword">lambda</span> example: {<span class="hljs-string">&quot;answer&quot;</span>: example[<span class="hljs-string">&quot;answers&quot;</span>][<span class="hljs-number">0</span>]}, remove_columns=[<span class="hljs-string">&quot;answer&quot;</span>, <span class="hljs-string">&quot;answers&quot;</span>]
<span class="hljs-meta">... </span>)`}}),ms=new g({props:{code:"dXBkYXRlZF9kYXRhc2V0JTIwJTNEJTIwdXBkYXRlZF9kYXRhc2V0LmZpbHRlcihsYW1iZGElMjB4JTNBJTIwbGVuKHglNUIlMjJ3b3JkcyUyMiU1RCklMjAlMkIlMjBsZW4oeCU1QiUyMnF1ZXN0aW9uJTIyJTVELnNwbGl0KCkpJTIwJTNDJTIwNTEyKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset = updated_dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;words&quot;</span>]) + <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;question&quot;</span>].split()) &lt; <span class="hljs-number">512</span>)'}}),us=new g({props:{code:"dXBkYXRlZF9kYXRhc2V0JTIwJTNEJTIwdXBkYXRlZF9kYXRhc2V0LnJlbW92ZV9jb2x1bW5zKCUyMndvcmRzJTIyKSUwQXVwZGF0ZWRfZGF0YXNldCUyMCUzRCUyMHVwZGF0ZWRfZGF0YXNldC5yZW1vdmVfY29sdW1ucyglMjJib3VuZGluZ19ib3hlcyUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset = updated_dataset.remove_columns(<span class="hljs-string">&quot;words&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset = updated_dataset.remove_columns(<span class="hljs-string">&quot;bounding_boxes&quot;</span>)`}}),xs=new g({props:{code:"dXBkYXRlZF9kYXRhc2V0JTVCJTIydHJhaW4lMjIlNUQlNUIxMSU1RCU1QiUyMmltYWdlJTIyJTVE",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>updated_dataset[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">11</span>][<span class="hljs-string">&quot;image&quot;</span>]'}}),ys=new E({}),fs=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMEElMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(model_checkpoint)`}}),Js=new E({}),Us=new g({props:{code:"aW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwcHJvY2Vzc29yLmltYWdlX3Byb2Nlc3NvciUwQSUwQSUwQWRlZiUyMGdldF9vY3Jfd29yZHNfYW5kX2JveGVzKGV4YW1wbGVzKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QmltYWdlLmNvbnZlcnQoJTIyUkdCJTIyKSUyMGZvciUyMGltYWdlJTIwaW4lMjBleGFtcGxlcyU1QiUyMmltYWdlJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwZW5jb2RlZF9pbnB1dHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2VzKSUwQSUwQSUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIyaW1hZ2UlMjIlNUQlMjAlM0QlMjBlbmNvZGVkX2lucHV0cy5waXhlbF92YWx1ZXMlMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMndvcmRzJTIyJTVEJTIwJTNEJTIwZW5jb2RlZF9pbnB1dHMud29yZHMlMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMmJveGVzJTIyJTVEJTIwJTNEJTIwZW5jb2RlZF9pbnB1dHMuYm94ZXMlMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBleGFtcGxlcw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = processor.image_processor


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">get_ocr_words_and_boxes</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    images = [image.convert(<span class="hljs-string">&quot;RGB&quot;</span>) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    encoded_inputs = image_processor(images)

<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;image&quot;</span>] = encoded_inputs.pixel_values
<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;words&quot;</span>] = encoded_inputs.words
<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;boxes&quot;</span>] = encoded_inputs.boxes

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> examples`}}),Cs=new g({props:{code:"ZGF0YXNldF93aXRoX29jciUyMCUzRCUyMHVwZGF0ZWRfZGF0YXNldC5tYXAoZ2V0X29jcl93b3Jkc19hbmRfYm94ZXMlMkMlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUyMGJhdGNoX3NpemUlM0QyKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset_with_ocr = updated_dataset.<span class="hljs-built_in">map</span>(get_ocr_words_and_boxes, batched=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">2</span>)'}}),Is=new E({}),_s=new g({props:{code:"dG9rZW5pemVyJTIwJTNEJTIwcHJvY2Vzc29yLnRva2VuaXplcg==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = processor.tokenizer'}}),Rs=new g({props:{code:"ZGVmJTIwc3ViZmluZGVyKHdvcmRzX2xpc3QlMkMlMjBhbnN3ZXJfbGlzdCklM0ElMEElMjAlMjAlMjAlMjBtYXRjaGVzJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwc3RhcnRfaW5kaWNlcyUyMCUzRCUyMCU1QiU1RCUwQSUyMCUyMCUyMCUyMGVuZF9pbmRpY2VzJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwZm9yJTIwaWR4JTJDJTIwaSUyMGluJTIwZW51bWVyYXRlKHJhbmdlKGxlbih3b3Jkc19saXN0KSkpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWYlMjB3b3Jkc19saXN0JTVCaSU1RCUyMCUzRCUzRCUyMGFuc3dlcl9saXN0JTVCMCU1RCUyMGFuZCUyMHdvcmRzX2xpc3QlNUJpJTIwJTNBJTIwaSUyMCUyQiUyMGxlbihhbnN3ZXJfbGlzdCklNUQlMjAlM0QlM0QlMjBhbnN3ZXJfbGlzdCUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1hdGNoZXMuYXBwZW5kKGFuc3dlcl9saXN0KSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHN0YXJ0X2luZGljZXMuYXBwZW5kKGlkeCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbmRfaW5kaWNlcy5hcHBlbmQoaWR4JTIwJTJCJTIwbGVuKGFuc3dlcl9saXN0KSUyMC0lMjAxKSUwQSUyMCUyMCUyMCUyMGlmJTIwbWF0Y2hlcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMG1hdGNoZXMlNUIwJTVEJTJDJTIwc3RhcnRfaW5kaWNlcyU1QjAlNUQlMkMlMjBlbmRfaW5kaWNlcyU1QjAlNUQlMEElMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwTm9uZSUyQyUyMDAlMkMlMjAw",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">subfinder</span>(<span class="hljs-params">words_list, answer_list</span>):
<span class="hljs-meta">... </span>    matches = []
<span class="hljs-meta">... </span>    start_indices = []
<span class="hljs-meta">... </span>    end_indices = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> idx, i <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(<span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(words_list))):
<span class="hljs-meta">... </span>        <span class="hljs-keyword">if</span> words_list[i] == answer_list[<span class="hljs-number">0</span>] <span class="hljs-keyword">and</span> words_list[i : i + <span class="hljs-built_in">len</span>(answer_list)] == answer_list:
<span class="hljs-meta">... </span>            matches.append(answer_list)
<span class="hljs-meta">... </span>            start_indices.append(idx)
<span class="hljs-meta">... </span>            end_indices.append(idx + <span class="hljs-built_in">len</span>(answer_list) - <span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> matches:
<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> matches[<span class="hljs-number">0</span>], start_indices[<span class="hljs-number">0</span>], end_indices[<span class="hljs-number">0</span>]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> <span class="hljs-literal">None</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>`}}),$s=new g({props:{code:"ZXhhbXBsZSUyMCUzRCUyMGRhdGFzZXRfd2l0aF9vY3IlNUIlMjJ0cmFpbiUyMiU1RCU1QjElNUQlMEF3b3JkcyUyMCUzRCUyMCU1QndvcmQubG93ZXIoKSUyMGZvciUyMHdvcmQlMjBpbiUyMGV4YW1wbGUlNUIlMjJ3b3JkcyUyMiU1RCU1RCUwQW1hdGNoJTJDJTIwd29yZF9pZHhfc3RhcnQlMkMlMjB3b3JkX2lkeF9lbmQlMjAlM0QlMjBzdWJmaW5kZXIod29yZHMlMkMlMjBleGFtcGxlJTVCJTIyYW5zd2VyJTIyJTVELmxvd2VyKCkuc3BsaXQoKSklMEFwcmludCglMjJRdWVzdGlvbiUzQSUyMCUyMiUyQyUyMGV4YW1wbGUlNUIlMjJxdWVzdGlvbiUyMiU1RCklMEFwcmludCglMjJXb3JkcyUzQSUyMiUyQyUyMHdvcmRzKSUwQXByaW50KCUyMkFuc3dlciUzQSUyMCUyMiUyQyUyMGV4YW1wbGUlNUIlMjJhbnN3ZXIlMjIlNUQpJTBBcHJpbnQoJTIyc3RhcnRfaW5kZXglMjIlMkMlMjB3b3JkX2lkeF9zdGFydCklMEFwcmludCglMjJlbmRfaW5kZXglMjIlMkMlMjB3b3JkX2lkeF9lbmQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = dataset_with_ocr[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>words = [word.lower() <span class="hljs-keyword">for</span> word <span class="hljs-keyword">in</span> example[<span class="hljs-string">&quot;words&quot;</span>]]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">match</span>, word_idx_start, word_idx_end = subfinder(words, example[<span class="hljs-string">&quot;answer&quot;</span>].lower().split())
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Question: &quot;</span>, example[<span class="hljs-string">&quot;question&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Words:&quot;</span>, words)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Answer: &quot;</span>, example[<span class="hljs-string">&quot;answer&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;start_index&quot;</span>, word_idx_start)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;end_index&quot;</span>, word_idx_end)
Question:  Who <span class="hljs-keyword">is</span> <span class="hljs-keyword">in</span>  cc <span class="hljs-keyword">in</span> this letter?
Words: [<span class="hljs-string">&#x27;wie&#x27;</span>, <span class="hljs-string">&#x27;baw&#x27;</span>, <span class="hljs-string">&#x27;brown&#x27;</span>, <span class="hljs-string">&#x27;&amp;&#x27;</span>, <span class="hljs-string">&#x27;williamson&#x27;</span>, <span class="hljs-string">&#x27;tobacco&#x27;</span>, <span class="hljs-string">&#x27;corporation&#x27;</span>, <span class="hljs-string">&#x27;research&#x27;</span>, <span class="hljs-string">&#x27;&amp;&#x27;</span>, <span class="hljs-string">&#x27;development&#x27;</span>, <span class="hljs-string">&#x27;internal&#x27;</span>, <span class="hljs-string">&#x27;correspondence&#x27;</span>, <span class="hljs-string">&#x27;to:&#x27;</span>, <span class="hljs-string">&#x27;r.&#x27;</span>, <span class="hljs-string">&#x27;h.&#x27;</span>, <span class="hljs-string">&#x27;honeycutt&#x27;</span>, <span class="hljs-string">&#x27;ce:&#x27;</span>, <span class="hljs-string">&#x27;t.f.&#x27;</span>, <span class="hljs-string">&#x27;riehl&#x27;</span>, <span class="hljs-string">&#x27;from:&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;c.j.&#x27;</span>, <span class="hljs-string">&#x27;cook&#x27;</span>, <span class="hljs-string">&#x27;date:&#x27;</span>, <span class="hljs-string">&#x27;may&#x27;</span>, <span class="hljs-string">&#x27;8,&#x27;</span>, <span class="hljs-string">&#x27;1995&#x27;</span>, <span class="hljs-string">&#x27;subject:&#x27;</span>, <span class="hljs-string">&#x27;review&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;existing&#x27;</span>, <span class="hljs-string">&#x27;brainstorming&#x27;</span>, <span class="hljs-string">&#x27;ideas/483&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;major&#x27;</span>, <span class="hljs-string">&#x27;function&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;product&#x27;</span>, <span class="hljs-string">&#x27;innovation&#x27;</span>, <span class="hljs-string">&#x27;graup&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;develop&#x27;</span>, <span class="hljs-string">&#x27;marketable&#x27;</span>, <span class="hljs-string">&#x27;nove!&#x27;</span>, <span class="hljs-string">&#x27;products&#x27;</span>, <span class="hljs-string">&#x27;that&#x27;</span>, <span class="hljs-string">&#x27;would&#x27;</span>, <span class="hljs-string">&#x27;be&#x27;</span>, <span class="hljs-string">&#x27;profitable&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;manufacture&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;sell.&#x27;</span>, <span class="hljs-string">&#x27;novel&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;defined&#x27;</span>, <span class="hljs-string">&#x27;as:&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;new&#x27;</span>, <span class="hljs-string">&#x27;kind,&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;different&#x27;</span>, <span class="hljs-string">&#x27;from&#x27;</span>, <span class="hljs-string">&#x27;anything&#x27;</span>, <span class="hljs-string">&#x27;seen&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;known&#x27;</span>, <span class="hljs-string">&#x27;before.&#x27;</span>, <span class="hljs-string">&#x27;innovation&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;defined&#x27;</span>, <span class="hljs-string">&#x27;as:&#x27;</span>, <span class="hljs-string">&#x27;something&#x27;</span>, <span class="hljs-string">&#x27;new&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;different&#x27;</span>, <span class="hljs-string">&#x27;introduced;&#x27;</span>, <span class="hljs-string">&#x27;act&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;innovating;&#x27;</span>, <span class="hljs-string">&#x27;introduction&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;new&#x27;</span>, <span class="hljs-string">&#x27;things&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;methods.&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;products&#x27;</span>, <span class="hljs-string">&#x27;may&#x27;</span>, <span class="hljs-string">&#x27;incorporate&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;latest&#x27;</span>, <span class="hljs-string">&#x27;technologies,&#x27;</span>, <span class="hljs-string">&#x27;materials&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;know-how&#x27;</span>, <span class="hljs-string">&#x27;available&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;give&#x27;</span>, <span class="hljs-string">&#x27;then&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;unique&#x27;</span>, <span class="hljs-string">&#x27;taste&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;look.&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;first&#x27;</span>, <span class="hljs-string">&#x27;task&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;product&#x27;</span>, <span class="hljs-string">&#x27;innovation&#x27;</span>, <span class="hljs-string">&#x27;group&#x27;</span>, <span class="hljs-string">&#x27;was&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;assemble,&#x27;</span>, <span class="hljs-string">&#x27;review&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;categorize&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;list&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;existing&#x27;</span>, <span class="hljs-string">&#x27;brainstorming&#x27;</span>, <span class="hljs-string">&#x27;ideas.&#x27;</span>, <span class="hljs-string">&#x27;ideas&#x27;</span>, <span class="hljs-string">&#x27;were&#x27;</span>, <span class="hljs-string">&#x27;grouped&#x27;</span>, <span class="hljs-string">&#x27;into&#x27;</span>, <span class="hljs-string">&#x27;two&#x27;</span>, <span class="hljs-string">&#x27;major&#x27;</span>, <span class="hljs-string">&#x27;categories&#x27;</span>, <span class="hljs-string">&#x27;labeled&#x27;</span>, <span class="hljs-string">&#x27;appearance&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;taste/aroma.&#x27;</span>, <span class="hljs-string">&#x27;these&#x27;</span>, <span class="hljs-string">&#x27;categories&#x27;</span>, <span class="hljs-string">&#x27;are&#x27;</span>, <span class="hljs-string">&#x27;used&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;novel&#x27;</span>, <span class="hljs-string">&#x27;products&#x27;</span>, <span class="hljs-string">&#x27;that&#x27;</span>, <span class="hljs-string">&#x27;may&#x27;</span>, <span class="hljs-string">&#x27;differ&#x27;</span>, <span class="hljs-string">&#x27;from&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;visual&#x27;</span>, <span class="hljs-string">&#x27;and/or&#x27;</span>, <span class="hljs-string">&#x27;taste/aroma&#x27;</span>, <span class="hljs-string">&#x27;point&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;view&#x27;</span>, <span class="hljs-string">&#x27;compared&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;canventional&#x27;</span>, <span class="hljs-string">&#x27;cigarettes.&#x27;</span>, <span class="hljs-string">&#x27;other&#x27;</span>, <span class="hljs-string">&#x27;categories&#x27;</span>, <span class="hljs-string">&#x27;include&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;combination&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;above,&#x27;</span>, <span class="hljs-string">&#x27;filters,&#x27;</span>, <span class="hljs-string">&#x27;packaging&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;brand&#x27;</span>, <span class="hljs-string">&#x27;extensions.&#x27;</span>, <span class="hljs-string">&#x27;appearance&#x27;</span>, <span class="hljs-string">&#x27;this&#x27;</span>, <span class="hljs-string">&#x27;category&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;used&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;novel&#x27;</span>, <span class="hljs-string">&#x27;cigarette&#x27;</span>, <span class="hljs-string">&#x27;constructions&#x27;</span>, <span class="hljs-string">&#x27;that&#x27;</span>, <span class="hljs-string">&#x27;yield&#x27;</span>, <span class="hljs-string">&#x27;visually&#x27;</span>, <span class="hljs-string">&#x27;different&#x27;</span>, <span class="hljs-string">&#x27;products&#x27;</span>, <span class="hljs-string">&#x27;with&#x27;</span>, <span class="hljs-string">&#x27;minimal&#x27;</span>, <span class="hljs-string">&#x27;changes&#x27;</span>, <span class="hljs-string">&#x27;in&#x27;</span>, <span class="hljs-string">&#x27;smoke&#x27;</span>, <span class="hljs-string">&#x27;chemistry&#x27;</span>, <span class="hljs-string">&#x27;two&#x27;</span>, <span class="hljs-string">&#x27;cigarettes&#x27;</span>, <span class="hljs-string">&#x27;in&#x27;</span>, <span class="hljs-string">&#x27;cne.&#x27;</span>, <span class="hljs-string">&#x27;emulti-plug&#x27;</span>, <span class="hljs-string">&#x27;te&#x27;</span>, <span class="hljs-string">&#x27;build&#x27;</span>, <span class="hljs-string">&#x27;yaur&#x27;</span>, <span class="hljs-string">&#x27;awn&#x27;</span>, <span class="hljs-string">&#x27;cigarette.&#x27;</span>, <span class="hljs-string">&#x27;eswitchable&#x27;</span>, <span class="hljs-string">&#x27;menthol&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;non&#x27;</span>, <span class="hljs-string">&#x27;menthol&#x27;</span>, <span class="hljs-string">&#x27;cigarette.&#x27;</span>, <span class="hljs-string">&#x27;*cigarettes&#x27;</span>, <span class="hljs-string">&#x27;with&#x27;</span>, <span class="hljs-string">&#x27;interspaced&#x27;</span>, <span class="hljs-string">&#x27;perforations&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;enable&#x27;</span>, <span class="hljs-string">&#x27;smoker&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;separate&#x27;</span>, <span class="hljs-string">&#x27;unburned&#x27;</span>, <span class="hljs-string">&#x27;section&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;future&#x27;</span>, <span class="hljs-string">&#x27;smoking.&#x27;</span>, <span class="hljs-string">&#x27;«short&#x27;</span>, <span class="hljs-string">&#x27;cigarette,&#x27;</span>, <span class="hljs-string">&#x27;tobacco&#x27;</span>, <span class="hljs-string">&#x27;section&#x27;</span>, <span class="hljs-string">&#x27;30&#x27;</span>, <span class="hljs-string">&#x27;mm.&#x27;</span>, <span class="hljs-string">&#x27;«extremely&#x27;</span>, <span class="hljs-string">&#x27;fast&#x27;</span>, <span class="hljs-string">&#x27;buming&#x27;</span>, <span class="hljs-string">&#x27;cigarette.&#x27;</span>, <span class="hljs-string">&#x27;«novel&#x27;</span>, <span class="hljs-string">&#x27;cigarette&#x27;</span>, <span class="hljs-string">&#x27;constructions&#x27;</span>, <span class="hljs-string">&#x27;that&#x27;</span>, <span class="hljs-string">&#x27;permit&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;significant&#x27;</span>, <span class="hljs-string">&#x27;reduction&#x27;</span>, <span class="hljs-string">&#x27;iretobacco&#x27;</span>, <span class="hljs-string">&#x27;weight&#x27;</span>, <span class="hljs-string">&#x27;while&#x27;</span>, <span class="hljs-string">&#x27;maintaining&#x27;</span>, <span class="hljs-string">&#x27;smoking&#x27;</span>, <span class="hljs-string">&#x27;mechanics&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;visual&#x27;</span>, <span class="hljs-string">&#x27;characteristics.&#x27;</span>, <span class="hljs-string">&#x27;higher&#x27;</span>, <span class="hljs-string">&#x27;basis&#x27;</span>, <span class="hljs-string">&#x27;weight&#x27;</span>, <span class="hljs-string">&#x27;paper:&#x27;</span>, <span class="hljs-string">&#x27;potential&#x27;</span>, <span class="hljs-string">&#x27;reduction&#x27;</span>, <span class="hljs-string">&#x27;in&#x27;</span>, <span class="hljs-string">&#x27;tobacco&#x27;</span>, <span class="hljs-string">&#x27;weight.&#x27;</span>, <span class="hljs-string">&#x27;«more&#x27;</span>, <span class="hljs-string">&#x27;rigid&#x27;</span>, <span class="hljs-string">&#x27;tobacco&#x27;</span>, <span class="hljs-string">&#x27;column;&#x27;</span>, <span class="hljs-string">&#x27;stiffing&#x27;</span>, <span class="hljs-string">&#x27;agent&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;tobacco;&#x27;</span>, <span class="hljs-string">&#x27;e.g.&#x27;</span>, <span class="hljs-string">&#x27;starch&#x27;</span>, <span class="hljs-string">&#x27;*colored&#x27;</span>, <span class="hljs-string">&#x27;tow&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;cigarette&#x27;</span>, <span class="hljs-string">&#x27;papers;&#x27;</span>, <span class="hljs-string">&#x27;seasonal&#x27;</span>, <span class="hljs-string">&#x27;promotions,&#x27;</span>, <span class="hljs-string">&#x27;e.g.&#x27;</span>, <span class="hljs-string">&#x27;pastel&#x27;</span>, <span class="hljs-string">&#x27;colored&#x27;</span>, <span class="hljs-string">&#x27;cigarettes&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;easter&#x27;</span>, <span class="hljs-string">&#x27;or&#x27;</span>, <span class="hljs-string">&#x27;in&#x27;</span>, <span class="hljs-string">&#x27;an&#x27;</span>, <span class="hljs-string">&#x27;ebony&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;ivory&#x27;</span>, <span class="hljs-string">&#x27;brand&#x27;</span>, <span class="hljs-string">&#x27;containing&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-string">&#x27;mixture&#x27;</span>, <span class="hljs-string">&#x27;of&#x27;</span>, <span class="hljs-string">&#x27;all&#x27;</span>, <span class="hljs-string">&#x27;black&#x27;</span>, <span class="hljs-string">&#x27;(black&#x27;</span>, <span class="hljs-string">&#x27;paper&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;tow)&#x27;</span>, <span class="hljs-string">&#x27;and&#x27;</span>, <span class="hljs-string">&#x27;ail&#x27;</span>, <span class="hljs-string">&#x27;white&#x27;</span>, <span class="hljs-string">&#x27;cigarettes.&#x27;</span>, <span class="hljs-string">&#x27;499150498&#x27;</span>]
Answer:  T.F. Riehl
start_index <span class="hljs-number">17</span>
end_index <span class="hljs-number">18</span>`}}),Bs=new g({props:{code:"ZW5jb2RpbmclMjAlM0QlMjB0b2tlbml6ZXIoZXhhbXBsZSU1QiUyMnF1ZXN0aW9uJTIyJTVEJTJDJTIwZXhhbXBsZSU1QiUyMndvcmRzJTIyJTVEJTJDJTIwZXhhbXBsZSU1QiUyMmJveGVzJTIyJTVEKSUwQXRva2VuaXplci5kZWNvZGUoZW5jb2RpbmclNUIlMjJpbnB1dF9pZHMlMjIlNUQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>encoding = tokenizer(example[<span class="hljs-string">&quot;question&quot;</span>], example[<span class="hljs-string">&quot;words&quot;</span>], example[<span class="hljs-string">&quot;boxes&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(encoding[<span class="hljs-string">&quot;input_ids&quot;</span>])
[CLS] who <span class="hljs-keyword">is</span> <span class="hljs-keyword">in</span> cc <span class="hljs-keyword">in</span> this letter? [SEP] wie baw brown &amp; williamson tobacco corporation research &amp; development ...`}}),Es=new g({props:{code:" ",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">encode_dataset</span>(<span class="hljs-params">examples, max_length=<span class="hljs-number">512</span></span>):
<span class="hljs-meta">... </span>    questions = examples[<span class="hljs-string">&quot;question&quot;</span>]
<span class="hljs-meta">... </span>    words = examples[<span class="hljs-string">&quot;words&quot;</span>]
<span class="hljs-meta">... </span>    boxes = examples[<span class="hljs-string">&quot;boxes&quot;</span>]
<span class="hljs-meta">... </span>    answers = examples[<span class="hljs-string">&quot;answer&quot;</span>]

<span class="hljs-meta">... </span>    <span class="hljs-comment"># encode the batch of examples and initialize the start_positions and end_positions</span>
<span class="hljs-meta">... </span>    encoding = tokenizer(questions, words, boxes, max_length=max_length, padding=<span class="hljs-string">&quot;max_length&quot;</span>, truncation=<span class="hljs-literal">True</span>)
<span class="hljs-meta">... </span>    start_positions = []
<span class="hljs-meta">... </span>    end_positions = []

<span class="hljs-meta">... </span>    <span class="hljs-comment"># loop through the examples in the batch</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(questions)):
<span class="hljs-meta">... </span>        cls_index = encoding[<span class="hljs-string">&quot;input_ids&quot;</span>][i].index(tokenizer.cls_token_id)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># find the position of the answer in example&#x27;s words</span>
<span class="hljs-meta">... </span>        words_example = [word.lower() <span class="hljs-keyword">for</span> word <span class="hljs-keyword">in</span> words[i]]
<span class="hljs-meta">... </span>        answer = answers[i]
<span class="hljs-meta">... </span>        <span class="hljs-keyword">match</span>, word_idx_start, word_idx_end = subfinder(words_example, answer.lower().split())

<span class="hljs-meta">... </span>        <span class="hljs-keyword">if</span> <span class="hljs-keyword">match</span>:
<span class="hljs-meta">... </span>            <span class="hljs-comment"># if match is found, use \`token_type_ids\` to find where words start in the encoding</span>
<span class="hljs-meta">... </span>            token_type_ids = encoding[<span class="hljs-string">&quot;token_type_ids&quot;</span>][i]
<span class="hljs-meta">... </span>            token_start_index = <span class="hljs-number">0</span>
<span class="hljs-meta">... </span>            <span class="hljs-keyword">while</span> token_type_ids[token_start_index] != <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>                token_start_index += <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>            token_end_index = <span class="hljs-built_in">len</span>(encoding[<span class="hljs-string">&quot;input_ids&quot;</span>][i]) - <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>            <span class="hljs-keyword">while</span> token_type_ids[token_end_index] != <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>                token_end_index -= <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>            word_ids = encoding.word_ids(i)[token_start_index : token_end_index + <span class="hljs-number">1</span>]
<span class="hljs-meta">... </span>            start_position = cls_index
<span class="hljs-meta">... </span>            end_position = cls_index

<span class="hljs-meta">... </span>            <span class="hljs-comment"># loop over word_ids and increase \`token_start_index\` until it matches the answer position in words</span>
<span class="hljs-meta">... </span>            <span class="hljs-comment"># once it matches, save the \`token_start_index\` as the \`start_position\` of the answer in the encoding</span>
<span class="hljs-meta">... </span>            <span class="hljs-keyword">for</span> <span class="hljs-built_in">id</span> <span class="hljs-keyword">in</span> word_ids:
<span class="hljs-meta">... </span>                <span class="hljs-keyword">if</span> <span class="hljs-built_in">id</span> == word_idx_start:
<span class="hljs-meta">... </span>                    start_position = token_start_index
<span class="hljs-meta">... </span>                <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>                    token_start_index += <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>            <span class="hljs-comment"># similarly loop over \`word_ids\` starting from the end to find the \`end_position\` of the answer</span>
<span class="hljs-meta">... </span>            <span class="hljs-keyword">for</span> <span class="hljs-built_in">id</span> <span class="hljs-keyword">in</span> word_ids[::-<span class="hljs-number">1</span>]:
<span class="hljs-meta">... </span>                <span class="hljs-keyword">if</span> <span class="hljs-built_in">id</span> == word_idx_end:
<span class="hljs-meta">... </span>                    end_position = token_end_index
<span class="hljs-meta">... </span>                <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>                    token_end_index -= <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>            start_positions.append(start_position)
<span class="hljs-meta">... </span>            end_positions.append(end_position)

<span class="hljs-meta">... </span>        <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>            start_positions.append(cls_index)
<span class="hljs-meta">... </span>            end_positions.append(cls_index)

<span class="hljs-meta">... </span>    encoding[<span class="hljs-string">&quot;image&quot;</span>] = examples[<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">... </span>    encoding[<span class="hljs-string">&quot;start_positions&quot;</span>] = start_positions
<span class="hljs-meta">... </span>    encoding[<span class="hljs-string">&quot;end_positions&quot;</span>] = end_positions

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> encoding`}}),Qs=new g({props:{code:"ZW5jb2RlZF90cmFpbl9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldF93aXRoX29jciU1QiUyMnRyYWluJTIyJTVELm1hcCglMEElMjAlMjAlMjAlMjBlbmNvZGVfZGF0YXNldCUyQyUyMGJhdGNoZWQlM0RUcnVlJTJDJTIwYmF0Y2hfc2l6ZSUzRDIlMkMlMjByZW1vdmVfY29sdW1ucyUzRGRhdGFzZXRfd2l0aF9vY3IlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMlMEEpJTBBZW5jb2RlZF90ZXN0X2RhdGFzZXQlMjAlM0QlMjBkYXRhc2V0X3dpdGhfb2NyJTVCJTIydGVzdCUyMiU1RC5tYXAoJTBBJTIwJTIwJTIwJTIwZW5jb2RlX2RhdGFzZXQlMkMlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUyMGJhdGNoX3NpemUlM0QyJTJDJTIwcmVtb3ZlX2NvbHVtbnMlM0RkYXRhc2V0X3dpdGhfb2NyJTVCJTIydGVzdCUyMiU1RC5jb2x1bW5fbmFtZXMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>encoded_train_dataset = dataset_with_ocr[<span class="hljs-string">&quot;train&quot;</span>].<span class="hljs-built_in">map</span>(
<span class="hljs-meta">... </span>    encode_dataset, batched=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">2</span>, remove_columns=dataset_with_ocr[<span class="hljs-string">&quot;train&quot;</span>].column_names
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>encoded_test_dataset = dataset_with_ocr[<span class="hljs-string">&quot;test&quot;</span>].<span class="hljs-built_in">map</span>(
<span class="hljs-meta">... </span>    encode_dataset, batched=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">2</span>, remove_columns=dataset_with_ocr[<span class="hljs-string">&quot;test&quot;</span>].column_names
<span class="hljs-meta">... </span>)`}}),qs=new g({props:{code:"ZW5jb2RlZF90cmFpbl9kYXRhc2V0LmZlYXR1cmVz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>encoded_train_dataset.features
{<span class="hljs-string">&#x27;image&#x27;</span>: <span class="hljs-type">Sequence</span>(feature=<span class="hljs-type">Sequence</span>(feature=<span class="hljs-type">Sequence</span>(feature=Value(dtype=<span class="hljs-string">&#x27;uint8&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;input_ids&#x27;</span>: <span class="hljs-type">Sequence</span>(feature=Value(dtype=<span class="hljs-string">&#x27;int32&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: <span class="hljs-type">Sequence</span>(feature=Value(dtype=<span class="hljs-string">&#x27;int8&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;attention_mask&#x27;</span>: <span class="hljs-type">Sequence</span>(feature=Value(dtype=<span class="hljs-string">&#x27;int8&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;bbox&#x27;</span>: <span class="hljs-type">Sequence</span>(feature=<span class="hljs-type">Sequence</span>(feature=Value(dtype=<span class="hljs-string">&#x27;int64&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;start_positions&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;int64&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;end_positions&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;int64&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>)}`}}),Ys=new E({}),Ss=new E({}),Ds=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckRvY3VtZW50UXVlc3Rpb25BbnN3ZXJpbmclMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckRvY3VtZW50UXVlc3Rpb25BbnN3ZXJpbmcuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForDocumentQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForDocumentQuestionAnswering.from_pretrained(model_checkpoint)`}}),Os=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBJTIzJTIwUkVQTEFDRSUyMFRISVMlMjBXSVRIJTIwWU9VUiUyMFJFUE8lMjBJRCUwQXJlcG9faWQlMjAlM0QlMjAlMjJNYXJpYUslMkZsYXlvdXRsbXYyLWJhc2UtdW5jYXNlZF9maW5ldHVuZWRfZG9jdnFhJTIyJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RyZXBvX2lkJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNENCUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9lcG9jaHMlM0QyMCUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RlcHMlM0QyMDAlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBsZWFybmluZ19yYXRlJTNENWUtNSUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfdG90YWxfbGltaXQlM0QyJTJDJTBBJTIwJTIwJTIwJTIwcmVtb3ZlX3VudXNlZF9jb2x1bW5zJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBwdXNoX3RvX2h1YiUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># REPLACE THIS WITH YOUR REPO ID</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>repo_id = <span class="hljs-string">&quot;MariaK/layoutlmv2-base-uncased_finetuned_docvqa&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=repo_id,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">20</span>,
<span class="hljs-meta">... </span>    save_steps=<span class="hljs-number">200</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">5e-5</span>,
<span class="hljs-meta">... </span>    save_total_limit=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    remove_unused_columns=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`}}),aa=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DefaultDataCollator()`}}),ta=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0RlbmNvZGVkX3RyYWluX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0RlbmNvZGVkX3Rlc3RfZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHByb2Nlc3NvciUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>    train_dataset=encoded_train_dataset,
<span class="hljs-meta">... </span>    eval_dataset=encoded_test_dataset,
<span class="hljs-meta">... </span>    tokenizer=processor,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),ea=new g({props:{code:"dHJhaW5lci5jcmVhdGVfbW9kZWxfY2FyZCgpJTBBdHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.create_model_card()
<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()`}}),pa=new E({}),oa=new g({props:{code:"ZXhhbXBsZSUyMCUzRCUyMGRhdGFzZXQlNUIlMjJ0ZXN0JTIyJTVEJTVCMiU1RCUwQXF1ZXN0aW9uJTIwJTNEJTIwZXhhbXBsZSU1QiUyMnF1ZXJ5JTIyJTVEJTVCJTIyZW4lMjIlNUQlMEFpbWFnZSUyMCUzRCUyMGV4YW1wbGUlNUIlMjJpbWFnZSUyMiU1RCUwQXByaW50KHF1ZXN0aW9uKSUwQXByaW50KGV4YW1wbGUlNUIlMjJhbnN3ZXJzJTIyJTVEKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-number">2</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>question = example[<span class="hljs-string">&quot;query&quot;</span>][<span class="hljs-string">&quot;en&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image = example[<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(question)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(example[<span class="hljs-string">&quot;answers&quot;</span>])
<span class="hljs-string">&#x27;Who is ‘presiding’ TRRF GENERAL SESSION (PART 1)?&#x27;</span>
[<span class="hljs-string">&#x27;TRRF Vice President&#x27;</span>, <span class="hljs-string">&#x27;lee a. waller&#x27;</span>]`}}),ha=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcWFfcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZSglMjJkb2N1bWVudC1xdWVzdGlvbi1hbnN3ZXJpbmclMjIlMkMlMjBtb2RlbCUzRCUyMk1hcmlhSyUyRmxheW91dGxtdjItYmFzZS11bmNhc2VkX2ZpbmV0dW5lZF9kb2N2cWElMjIpJTBBcWFfcGlwZWxpbmUoaW1hZ2UlMkMlMjBxdWVzdGlvbik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>qa_pipeline = pipeline(<span class="hljs-string">&quot;document-question-answering&quot;</span>, model=<span class="hljs-string">&quot;MariaK/layoutlmv2-base-uncased_finetuned_docvqa&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>qa_pipeline(image, question)
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9949808120727539</span>,
  <span class="hljs-string">&#x27;answer&#x27;</span>: <span class="hljs-string">&#x27;Lee A. Waller&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">55</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`}}),ma=new g({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Byb2Nlc3NvciUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWxGb3JEb2N1bWVudFF1ZXN0aW9uQW5zd2VyaW5nJTBBJTBBcHJvY2Vzc29yJTIwJTNEJTIwQXV0b1Byb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyTWFyaWFLJTJGbGF5b3V0bG12Mi1iYXNlLXVuY2FzZWRfZmluZXR1bmVkX2RvY3ZxYSUyMiklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckRvY3VtZW50UXVlc3Rpb25BbnN3ZXJpbmcuZnJvbV9wcmV0cmFpbmVkKCUyMk1hcmlhSyUyRmxheW91dGxtdjItYmFzZS11bmNhc2VkX2ZpbmV0dW5lZF9kb2N2cWElMjIpJTBBJTBBd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMGVuY29kaW5nJTIwJTNEJTIwcHJvY2Vzc29yKGltYWdlLmNvbnZlcnQoJTIyUkdCJTIyKSUyQyUyMHF1ZXN0aW9uJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKiplbmNvZGluZyklMEElMjAlMjAlMjAlMjBzdGFydF9sb2dpdHMlMjAlM0QlMjBvdXRwdXRzLnN0YXJ0X2xvZ2l0cyUwQSUyMCUyMCUyMCUyMGVuZF9sb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmVuZF9sb2dpdHMlMEElMjAlMjAlMjAlMjBwcmVkaWN0ZWRfc3RhcnRfaWR4JTIwJTNEJTIwc3RhcnRfbG9naXRzLmFyZ21heCgtMSkuaXRlbSgpJTBBJTIwJTIwJTIwJTIwcHJlZGljdGVkX2VuZF9pZHglMjAlM0QlMjBlbmRfbG9naXRzLmFyZ21heCgtMSkuaXRlbSgpJTBBJTBBcHJvY2Vzc29yLnRva2VuaXplci5kZWNvZGUoZW5jb2RpbmcuaW5wdXRfaWRzLnNxdWVlemUoKSU1QnByZWRpY3RlZF9zdGFydF9pZHglMjAlM0ElMjBwcmVkaWN0ZWRfZW5kX2lkeCUyMCUyQiUyMDElNUQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForDocumentQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;MariaK/layoutlmv2-base-uncased_finetuned_docvqa&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForDocumentQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;MariaK/layoutlmv2-base-uncased_finetuned_docvqa&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    encoding = processor(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>), question, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">... </span>    outputs = model(**encoding)
<span class="hljs-meta">... </span>    start_logits = outputs.start_logits
<span class="hljs-meta">... </span>    end_logits = outputs.end_logits
<span class="hljs-meta">... </span>    predicted_start_idx = start_logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-meta">... </span>    predicted_end_idx = end_logits.argmax(-<span class="hljs-number">1</span>).item()

<span class="hljs-meta">&gt;&gt;&gt; </span>processor.tokenizer.decode(encoding.input_ids.squeeze()[predicted_start_idx : predicted_end_idx + <span class="hljs-number">1</span>])
<span class="hljs-string">&#x27;lee a. waller&#x27;</span>`}}),{c(){w=p("meta"),F=l(),b=p("p"),f=l(),J=p("h1"),y=p("a"),U=p("span"),o(Q.$$.fragment),ut=l(),ua=p("span"),ua.textContent=Ut,Ra=l(),o(z.$$.fragment),Xa=l(),q=p("p"),q.textContent=Tt,$a=l(),Y=p("p"),Y.textContent=Ct,Ga=l(),H=p("ul"),H.innerHTML=It,Ba=l(),o(A.$$.fragment),Wa=l(),S=p("p"),S.textContent=vt,Na=l(),L=p("p"),L.textContent=_t,Va=l(),o(P.$$.fragment),Ea=l(),o(D.$$.fragment),Fa=l(),o(K.$$.fragment),Qa=l(),O=p("p"),O.textContent=kt,za=l(),ss=p("p"),ss.textContent=Zt,qa=l(),o(as.$$.fragment),Ya=l(),ns=p("p"),ns.textContent=At,Ha=l(),o(ts.$$.fragment),Sa=l(),T=p("h2"),R=p("a"),Ua=p("span"),o(ls.$$.fragment),gt=l(),ga=p("span"),ga.textContent=Rt,La=l(),es=p("p"),es.innerHTML=Xt,Pa=l(),o(ps.$$.fragment),Da=l(),is=p("p"),is.textContent=$t,Ka=l(),o(rs.$$.fragment),Oa=l(),os=p("p"),os.textContent=Gt,sn=l(),cs=p("ul"),cs.innerHTML=Bt,an=l(),hs=p("p"),hs.innerHTML=Wt,nn=l(),o(js.$$.fragment),tn=l(),ds=p("p"),ds.innerHTML=Nt,ln=l(),o(ms.$$.fragment),en=l(),Ms=p("p"),Ms.innerHTML=Vt,pn=l(),o(us.$$.fragment),rn=l(),gs=p("p"),gs.textContent=Et,on=l(),o(xs.$$.fragment),cn=l(),X=p("div"),X.innerHTML=Ft,hn=l(),C=p("h2"),$=p("a"),Ta=p("span"),o(ys.$$.fragment),xt=l(),xa=p("span"),xa.textContent=Qt,jn=l(),ws=p("p"),ws.innerHTML=zt,dn=l(),o(fs.$$.fragment),mn=l(),I=p("h3"),G=p("a"),Ca=p("span"),o(Js.$$.fragment),yt=l(),ya=p("span"),ya.textContent=qt,Mn=l(),bs=p("p"),bs.innerHTML=Yt,un=l(),o(Us.$$.fragment),gn=l(),Ts=p("p"),Ts.innerHTML=Ht,xn=l(),o(Cs.$$.fragment),yn=l(),v=p("h3"),B=p("a"),Ia=p("span"),o(Is.$$.fragment),wt=l(),wa=p("span"),wa.textContent=St,wn=l(),vs=p("p"),vs.innerHTML=Lt,fn=l(),o(_s.$$.fragment),Jn=l(),ks=p("p"),ks.innerHTML=Pt,bn=l(),Zs=p("p"),Zs.textContent=Dt,Un=l(),As=p("p"),As.innerHTML=Kt,Tn=l(),o(Rs.$$.fragment),Cn=l(),Xs=p("p"),Xs.textContent=Ot,In=l(),o($s.$$.fragment),vn=l(),Gs=p("p"),Gs.textContent=sl,_n=l(),o(Bs.$$.fragment),kn=l(),Ws=p("p"),Ws.textContent=al,Zn=l(),Ns=p("ul"),Ns.innerHTML=nl,An=l(),Vs=p("p"),Vs.textContent=tl,Rn=l(),o(Es.$$.fragment),Xn=l(),Fs=p("p"),Fs.textContent=ll,$n=l(),o(Qs.$$.fragment),Gn=l(),zs=p("p"),zs.textContent=el,Bn=l(),o(qs.$$.fragment),Wn=l(),_=p("h2"),W=p("a"),va=p("span"),o(Ys.$$.fragment),ft=l(),fa=p("span"),fa.textContent=pl,Nn=l(),Hs=p("p"),Hs.innerHTML=il,Vn=l(),k=p("h2"),N=p("a"),_a=p("span"),o(Ss.$$.fragment),Jt=l(),Ja=p("span"),Ja.textContent=rl,En=l(),Ls=p("p"),Ls.textContent=ol,Fn=l(),Ps=p("ul"),Ps.innerHTML=cl,Qn=l(),o(Ds.$$.fragment),zn=l(),Ks=p("p"),Ks.innerHTML=hl,qn=l(),o(Os.$$.fragment),Yn=l(),sa=p("p"),sa.textContent=jl,Hn=l(),o(aa.$$.fragment),Sn=l(),na=p("p"),na.innerHTML=dl,Ln=l(),o(ta.$$.fragment),Pn=l(),la=p("p"),la.innerHTML=ml,Dn=l(),o(ea.$$.fragment),Kn=l(),Z=p("h2"),V=p("a"),ka=p("span"),o(pa.$$.fragment),bt=l(),ba=p("span"),ba.textContent=Ml,On=l(),ia=p("p"),ia.innerHTML=ul,st=l(),ra=p("p"),ra.textContent=gl,at=l(),o(oa.$$.fragment),nt=l(),ca=p("p"),ca.textContent=xl,tt=l(),o(ha.$$.fragment),lt=l(),ja=p("p"),ja.textContent=yl,et=l(),da=p("ol"),da.innerHTML=wl,pt=l(),o(ma.$$.fragment),it=l(),Za=p("p"),this.h()},l(s){const a=Fl("svelte-1phssyn",document.head);w=i(a,"META",{name:!0,content:!0}),a.forEach(n),F=e(s),b=i(s,"P",{}),x(b).forEach(n),f=e(s),J=i(s,"H1",{class:!0});var Ma=x(J);y=i(Ma,"A",{id:!0,class:!0,href:!0});var fl=x(y);U=i(fl,"SPAN",{});var Jl=x(U);c(Q.$$.fragment,Jl),Jl.forEach(n),fl.forEach(n),ut=e(Ma),ua=i(Ma,"SPAN",{"data-svelte-h":!0}),r(ua)!=="svelte-ypkay6"&&(ua.textContent=Ut),Ma.forEach(n),Ra=e(s),c(z.$$.fragment,s),Xa=e(s),q=i(s,"P",{"data-svelte-h":!0}),r(q)!=="svelte-1c1m6de"&&(q.textContent=Tt),$a=e(s),Y=i(s,"P",{"data-svelte-h":!0}),r(Y)!=="svelte-ku8orh"&&(Y.textContent=Ct),Ga=e(s),H=i(s,"UL",{"data-svelte-h":!0}),r(H)!=="svelte-1g8eree"&&(H.innerHTML=It),Ba=e(s),c(A.$$.fragment,s),Wa=e(s),S=i(s,"P",{"data-svelte-h":!0}),r(S)!=="svelte-1svbrv5"&&(S.textContent=vt),Na=e(s),L=i(s,"P",{"data-svelte-h":!0}),r(L)!=="svelte-17fjxql"&&(L.textContent=_t),Va=e(s),c(P.$$.fragment,s),Ea=e(s),c(D.$$.fragment,s),Fa=e(s),c(K.$$.fragment,s),Qa=e(s),O=i(s,"P",{"data-svelte-h":!0}),r(O)!=="svelte-hsz112"&&(O.textContent=kt),za=e(s),ss=i(s,"P",{"data-svelte-h":!0}),r(ss)!=="svelte-1yqpblu"&&(ss.textContent=Zt),qa=e(s),c(as.$$.fragment,s),Ya=e(s),ns=i(s,"P",{"data-svelte-h":!0}),r(ns)!=="svelte-1us2g34"&&(ns.textContent=At),Ha=e(s),c(ts.$$.fragment,s),Sa=e(s),T=i(s,"H2",{class:!0});var ot=x(T);R=i(ot,"A",{id:!0,class:!0,href:!0});var bl=x(R);Ua=i(bl,"SPAN",{});var Ul=x(Ua);c(ls.$$.fragment,Ul),Ul.forEach(n),bl.forEach(n),gt=e(ot),ga=i(ot,"SPAN",{"data-svelte-h":!0}),r(ga)!=="svelte-1sbjexa"&&(ga.textContent=Rt),ot.forEach(n),La=e(s),es=i(s,"P",{"data-svelte-h":!0}),r(es)!=="svelte-xkaeyi"&&(es.innerHTML=Xt),Pa=e(s),c(ps.$$.fragment,s),Da=e(s),is=i(s,"P",{"data-svelte-h":!0}),r(is)!=="svelte-18ggx10"&&(is.textContent=$t),Ka=e(s),c(rs.$$.fragment,s),Oa=e(s),os=i(s,"P",{"data-svelte-h":!0}),r(os)!=="svelte-1fi388d"&&(os.textContent=Gt),sn=e(s),cs=i(s,"UL",{"data-svelte-h":!0}),r(cs)!=="svelte-12b5dxa"&&(cs.innerHTML=Bt),an=e(s),hs=i(s,"P",{"data-svelte-h":!0}),r(hs)!=="svelte-1h0f0qo"&&(hs.innerHTML=Wt),nn=e(s),c(js.$$.fragment,s),tn=e(s),ds=i(s,"P",{"data-svelte-h":!0}),r(ds)!=="svelte-x5p0j2"&&(ds.innerHTML=Nt),ln=e(s),c(ms.$$.fragment,s),en=e(s),Ms=i(s,"P",{"data-svelte-h":!0}),r(Ms)!=="svelte-bu07c0"&&(Ms.innerHTML=Vt),pn=e(s),c(us.$$.fragment,s),rn=e(s),gs=i(s,"P",{"data-svelte-h":!0}),r(gs)!=="svelte-1vy80t"&&(gs.textContent=Et),on=e(s),c(xs.$$.fragment,s),cn=e(s),X=i(s,"DIV",{class:!0,"data-svelte-h":!0}),r(X)!=="svelte-q63tj1"&&(X.innerHTML=Ft),hn=e(s),C=i(s,"H2",{class:!0});var ct=x(C);$=i(ct,"A",{id:!0,class:!0,href:!0});var Tl=x($);Ta=i(Tl,"SPAN",{});var Cl=x(Ta);c(ys.$$.fragment,Cl),Cl.forEach(n),Tl.forEach(n),xt=e(ct),xa=i(ct,"SPAN",{"data-svelte-h":!0}),r(xa)!=="svelte-171xy48"&&(xa.textContent=Qt),ct.forEach(n),jn=e(s),ws=i(s,"P",{"data-svelte-h":!0}),r(ws)!=="svelte-2t543m"&&(ws.innerHTML=zt),dn=e(s),c(fs.$$.fragment,s),mn=e(s),I=i(s,"H3",{class:!0});var ht=x(I);G=i(ht,"A",{id:!0,class:!0,href:!0});var Il=x(G);Ca=i(Il,"SPAN",{});var vl=x(Ca);c(Js.$$.fragment,vl),vl.forEach(n),Il.forEach(n),yt=e(ht),ya=i(ht,"SPAN",{"data-svelte-h":!0}),r(ya)!=="svelte-76kkmc"&&(ya.textContent=qt),ht.forEach(n),Mn=e(s),bs=i(s,"P",{"data-svelte-h":!0}),r(bs)!=="svelte-1u7369n"&&(bs.innerHTML=Yt),un=e(s),c(Us.$$.fragment,s),gn=e(s),Ts=i(s,"P",{"data-svelte-h":!0}),r(Ts)!=="svelte-1rxmj99"&&(Ts.innerHTML=Ht),xn=e(s),c(Cs.$$.fragment,s),yn=e(s),v=i(s,"H3",{class:!0});var jt=x(v);B=i(jt,"A",{id:!0,class:!0,href:!0});var _l=x(B);Ia=i(_l,"SPAN",{});var kl=x(Ia);c(Is.$$.fragment,kl),kl.forEach(n),_l.forEach(n),wt=e(jt),wa=i(jt,"SPAN",{"data-svelte-h":!0}),r(wa)!=="svelte-1epmnus"&&(wa.textContent=St),jt.forEach(n),wn=e(s),vs=i(s,"P",{"data-svelte-h":!0}),r(vs)!=="svelte-dfarfe"&&(vs.innerHTML=Lt),fn=e(s),c(_s.$$.fragment,s),Jn=e(s),ks=i(s,"P",{"data-svelte-h":!0}),r(ks)!=="svelte-12sojfo"&&(ks.innerHTML=Pt),bn=e(s),Zs=i(s,"P",{"data-svelte-h":!0}),r(Zs)!=="svelte-1kkerbo"&&(Zs.textContent=Dt),Un=e(s),As=i(s,"P",{"data-svelte-h":!0}),r(As)!=="svelte-1wppb4o"&&(As.innerHTML=Kt),Tn=e(s),c(Rs.$$.fragment,s),Cn=e(s),Xs=i(s,"P",{"data-svelte-h":!0}),r(Xs)!=="svelte-19pibjd"&&(Xs.textContent=Ot),In=e(s),c($s.$$.fragment,s),vn=e(s),Gs=i(s,"P",{"data-svelte-h":!0}),r(Gs)!=="svelte-19lp6r8"&&(Gs.textContent=sl),_n=e(s),c(Bs.$$.fragment,s),kn=e(s),Ws=i(s,"P",{"data-svelte-h":!0}),r(Ws)!=="svelte-1tk94l"&&(Ws.textContent=al),Zn=e(s),Ns=i(s,"UL",{"data-svelte-h":!0}),r(Ns)!=="svelte-zfehno"&&(Ns.innerHTML=nl),An=e(s),Vs=i(s,"P",{"data-svelte-h":!0}),r(Vs)!=="svelte-701rvg"&&(Vs.textContent=tl),Rn=e(s),c(Es.$$.fragment,s),Xn=e(s),Fs=i(s,"P",{"data-svelte-h":!0}),r(Fs)!=="svelte-1ori799"&&(Fs.textContent=ll),$n=e(s),c(Qs.$$.fragment,s),Gn=e(s),zs=i(s,"P",{"data-svelte-h":!0}),r(zs)!=="svelte-upxsp"&&(zs.textContent=el),Bn=e(s),c(qs.$$.fragment,s),Wn=e(s),_=i(s,"H2",{class:!0});var dt=x(_);W=i(dt,"A",{id:!0,class:!0,href:!0});var Zl=x(W);va=i(Zl,"SPAN",{});var Al=x(va);c(Ys.$$.fragment,Al),Al.forEach(n),Zl.forEach(n),ft=e(dt),fa=i(dt,"SPAN",{"data-svelte-h":!0}),r(fa)!=="svelte-rkze07"&&(fa.textContent=pl),dt.forEach(n),Nn=e(s),Hs=i(s,"P",{"data-svelte-h":!0}),r(Hs)!=="svelte-132ulnz"&&(Hs.innerHTML=il),Vn=e(s),k=i(s,"H2",{class:!0});var mt=x(k);N=i(mt,"A",{id:!0,class:!0,href:!0});var Rl=x(N);_a=i(Rl,"SPAN",{});var Xl=x(_a);c(Ss.$$.fragment,Xl),Xl.forEach(n),Rl.forEach(n),Jt=e(mt),Ja=i(mt,"SPAN",{"data-svelte-h":!0}),r(Ja)!=="svelte-5arm0l"&&(Ja.textContent=rl),mt.forEach(n),En=e(s),Ls=i(s,"P",{"data-svelte-h":!0}),r(Ls)!=="svelte-10f6ay"&&(Ls.textContent=ol),Fn=e(s),Ps=i(s,"UL",{"data-svelte-h":!0}),r(Ps)!=="svelte-e4ikd3"&&(Ps.innerHTML=cl),Qn=e(s),c(Ds.$$.fragment,s),zn=e(s),Ks=i(s,"P",{"data-svelte-h":!0}),r(Ks)!=="svelte-goi2k9"&&(Ks.innerHTML=hl),qn=e(s),c(Os.$$.fragment,s),Yn=e(s),sa=i(s,"P",{"data-svelte-h":!0}),r(sa)!=="svelte-1gq6t8w"&&(sa.textContent=jl),Hn=e(s),c(aa.$$.fragment,s),Sn=e(s),na=i(s,"P",{"data-svelte-h":!0}),r(na)!=="svelte-14n8grx"&&(na.innerHTML=dl),Ln=e(s),c(ta.$$.fragment,s),Pn=e(s),la=i(s,"P",{"data-svelte-h":!0}),r(la)!=="svelte-gilssp"&&(la.innerHTML=ml),Dn=e(s),c(ea.$$.fragment,s),Kn=e(s),Z=i(s,"H2",{class:!0});var Mt=x(Z);V=i(Mt,"A",{id:!0,class:!0,href:!0});var $l=x(V);ka=i($l,"SPAN",{});var Gl=x(ka);c(pa.$$.fragment,Gl),Gl.forEach(n),$l.forEach(n),bt=e(Mt),ba=i(Mt,"SPAN",{"data-svelte-h":!0}),r(ba)!=="svelte-199uz7g"&&(ba.textContent=Ml),Mt.forEach(n),On=e(s),ia=i(s,"P",{"data-svelte-h":!0}),r(ia)!=="svelte-1kz9mfc"&&(ia.innerHTML=ul),st=e(s),ra=i(s,"P",{"data-svelte-h":!0}),r(ra)!=="svelte-1wtngfz"&&(ra.textContent=gl),at=e(s),c(oa.$$.fragment,s),nt=e(s),ca=i(s,"P",{"data-svelte-h":!0}),r(ca)!=="svelte-mcchgg"&&(ca.textContent=xl),tt=e(s),c(ha.$$.fragment,s),lt=e(s),ja=i(s,"P",{"data-svelte-h":!0}),r(ja)!=="svelte-o6117l"&&(ja.textContent=yl),et=e(s),da=i(s,"OL",{"data-svelte-h":!0}),r(da)!=="svelte-19rdijs"&&(da.innerHTML=wl),pt=e(s),c(ma.$$.fragment,s),it=e(s),Za=i(s,"P",{}),x(Za).forEach(n),this.h()},h(){M(w,"name","hf:doc:metadata"),M(w,"content",JSON.stringify(Hl)),M(y,"id","document-question-answering"),M(y,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(y,"href","#document-question-answering"),M(J,"class","relative group"),M(R,"id","load-the-data"),M(R,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(R,"href","#load-the-data"),M(T,"class","relative group"),M(X,"class","flex justify-center"),M($,"id","preprocess-the-data"),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"),M($,"href","#preprocess-the-data"),M(C,"class","relative group"),M(G,"id","preprocessing-document-images"),M(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"),M(G,"href","#preprocessing-document-images"),M(I,"class","relative group"),M(B,"id","preprocessing-text-data"),M(B,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(B,"href","#preprocessing-text-data"),M(v,"class","relative group"),M(W,"id","evaluation"),M(W,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(W,"href","#evaluation"),M(_,"class","relative group"),M(N,"id","train"),M(N,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(N,"href","#train"),M(k,"class","relative group"),M(V,"id","inference"),M(V,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),M(V,"href","#inference"),M(Z,"class","relative group")},m(s,a){u(document.head,w),t(s,F,a),t(s,b,a),t(s,f,a),t(s,J,a),u(J,y),u(y,U),h(Q,U,null),u(J,ut),u(J,ua),t(s,Ra,a),h(z,s,a),t(s,Xa,a),t(s,q,a),t(s,$a,a),t(s,Y,a),t(s,Ga,a),t(s,H,a),t(s,Ba,a),h(A,s,a),t(s,Wa,a),t(s,S,a),t(s,Na,a),t(s,L,a),t(s,Va,a),h(P,s,a),t(s,Ea,a),h(D,s,a),t(s,Fa,a),h(K,s,a),t(s,Qa,a),t(s,O,a),t(s,za,a),t(s,ss,a),t(s,qa,a),h(as,s,a),t(s,Ya,a),t(s,ns,a),t(s,Ha,a),h(ts,s,a),t(s,Sa,a),t(s,T,a),u(T,R),u(R,Ua),h(ls,Ua,null),u(T,gt),u(T,ga),t(s,La,a),t(s,es,a),t(s,Pa,a),h(ps,s,a),t(s,Da,a),t(s,is,a),t(s,Ka,a),h(rs,s,a),t(s,Oa,a),t(s,os,a),t(s,sn,a),t(s,cs,a),t(s,an,a),t(s,hs,a),t(s,nn,a),h(js,s,a),t(s,tn,a),t(s,ds,a),t(s,ln,a),h(ms,s,a),t(s,en,a),t(s,Ms,a),t(s,pn,a),h(us,s,a),t(s,rn,a),t(s,gs,a),t(s,on,a),h(xs,s,a),t(s,cn,a),t(s,X,a),t(s,hn,a),t(s,C,a),u(C,$),u($,Ta),h(ys,Ta,null),u(C,xt),u(C,xa),t(s,jn,a),t(s,ws,a),t(s,dn,a),h(fs,s,a),t(s,mn,a),t(s,I,a),u(I,G),u(G,Ca),h(Js,Ca,null),u(I,yt),u(I,ya),t(s,Mn,a),t(s,bs,a),t(s,un,a),h(Us,s,a),t(s,gn,a),t(s,Ts,a),t(s,xn,a),h(Cs,s,a),t(s,yn,a),t(s,v,a),u(v,B),u(B,Ia),h(Is,Ia,null),u(v,wt),u(v,wa),t(s,wn,a),t(s,vs,a),t(s,fn,a),h(_s,s,a),t(s,Jn,a),t(s,ks,a),t(s,bn,a),t(s,Zs,a),t(s,Un,a),t(s,As,a),t(s,Tn,a),h(Rs,s,a),t(s,Cn,a),t(s,Xs,a),t(s,In,a),h($s,s,a),t(s,vn,a),t(s,Gs,a),t(s,_n,a),h(Bs,s,a),t(s,kn,a),t(s,Ws,a),t(s,Zn,a),t(s,Ns,a),t(s,An,a),t(s,Vs,a),t(s,Rn,a),h(Es,s,a),t(s,Xn,a),t(s,Fs,a),t(s,$n,a),h(Qs,s,a),t(s,Gn,a),t(s,zs,a),t(s,Bn,a),h(qs,s,a),t(s,Wn,a),t(s,_,a),u(_,W),u(W,va),h(Ys,va,null),u(_,ft),u(_,fa),t(s,Nn,a),t(s,Hs,a),t(s,Vn,a),t(s,k,a),u(k,N),u(N,_a),h(Ss,_a,null),u(k,Jt),u(k,Ja),t(s,En,a),t(s,Ls,a),t(s,Fn,a),t(s,Ps,a),t(s,Qn,a),h(Ds,s,a),t(s,zn,a),t(s,Ks,a),t(s,qn,a),h(Os,s,a),t(s,Yn,a),t(s,sa,a),t(s,Hn,a),h(aa,s,a),t(s,Sn,a),t(s,na,a),t(s,Ln,a),h(ta,s,a),t(s,Pn,a),t(s,la,a),t(s,Dn,a),h(ea,s,a),t(s,Kn,a),t(s,Z,a),u(Z,V),u(V,ka),h(pa,ka,null),u(Z,bt),u(Z,ba),t(s,On,a),t(s,ia,a),t(s,st,a),t(s,ra,a),t(s,at,a),h(oa,s,a),t(s,nt,a),t(s,ca,a),t(s,tt,a),h(ha,s,a),t(s,lt,a),t(s,ja,a),t(s,et,a),t(s,da,a),t(s,pt,a),h(ma,s,a),t(s,it,a),t(s,Za,a),rt=!0},p(s,[a]){const Ma={};a&2&&(Ma.$$scope={dirty:a,ctx:s}),A.$set(Ma)},i(s){rt||(j(Q.$$.fragment,s),j(z.$$.fragment,s),j(A.$$.fragment,s),j(P.$$.fragment,s),j(D.$$.fragment,s),j(K.$$.fragment,s),j(as.$$.fragment,s),j(ts.$$.fragment,s),j(ls.$$.fragment,s),j(ps.$$.fragment,s),j(rs.$$.fragment,s),j(js.$$.fragment,s),j(ms.$$.fragment,s),j(us.$$.fragment,s),j(xs.$$.fragment,s),j(ys.$$.fragment,s),j(fs.$$.fragment,s),j(Js.$$.fragment,s),j(Us.$$.fragment,s),j(Cs.$$.fragment,s),j(Is.$$.fragment,s),j(_s.$$.fragment,s),j(Rs.$$.fragment,s),j($s.$$.fragment,s),j(Bs.$$.fragment,s),j(Es.$$.fragment,s),j(Qs.$$.fragment,s),j(qs.$$.fragment,s),j(Ys.$$.fragment,s),j(Ss.$$.fragment,s),j(Ds.$$.fragment,s),j(Os.$$.fragment,s),j(aa.$$.fragment,s),j(ta.$$.fragment,s),j(ea.$$.fragment,s),j(pa.$$.fragment,s),j(oa.$$.fragment,s),j(ha.$$.fragment,s),j(ma.$$.fragment,s),rt=!0)},o(s){d(Q.$$.fragment,s),d(z.$$.fragment,s),d(A.$$.fragment,s),d(P.$$.fragment,s),d(D.$$.fragment,s),d(K.$$.fragment,s),d(as.$$.fragment,s),d(ts.$$.fragment,s),d(ls.$$.fragment,s),d(ps.$$.fragment,s),d(rs.$$.fragment,s),d(js.$$.fragment,s),d(ms.$$.fragment,s),d(us.$$.fragment,s),d(xs.$$.fragment,s),d(ys.$$.fragment,s),d(fs.$$.fragment,s),d(Js.$$.fragment,s),d(Us.$$.fragment,s),d(Cs.$$.fragment,s),d(Is.$$.fragment,s),d(_s.$$.fragment,s),d(Rs.$$.fragment,s),d($s.$$.fragment,s),d(Bs.$$.fragment,s),d(Es.$$.fragment,s),d(Qs.$$.fragment,s),d(qs.$$.fragment,s),d(Ys.$$.fragment,s),d(Ss.$$.fragment,s),d(Ds.$$.fragment,s),d(Os.$$.fragment,s),d(aa.$$.fragment,s),d(ta.$$.fragment,s),d(ea.$$.fragment,s),d(pa.$$.fragment,s),d(oa.$$.fragment,s),d(ha.$$.fragment,s),d(ma.$$.fragment,s),rt=!1},d(s){s&&(n(F),n(b),n(f),n(J),n(Ra),n(Xa),n(q),n($a),n(Y),n(Ga),n(H),n(Ba),n(Wa),n(S),n(Na),n(L),n(Va),n(Ea),n(Fa),n(Qa),n(O),n(za),n(ss),n(qa),n(Ya),n(ns),n(Ha),n(Sa),n(T),n(La),n(es),n(Pa),n(Da),n(is),n(Ka),n(Oa),n(os),n(sn),n(cs),n(an),n(hs),n(nn),n(tn),n(ds),n(ln),n(en),n(Ms),n(pn),n(rn),n(gs),n(on),n(cn),n(X),n(hn),n(C),n(jn),n(ws),n(dn),n(mn),n(I),n(Mn),n(bs),n(un),n(gn),n(Ts),n(xn),n(yn),n(v),n(wn),n(vs),n(fn),n(Jn),n(ks),n(bn),n(Zs),n(Un),n(As),n(Tn),n(Cn),n(Xs),n(In),n(vn),n(Gs),n(_n),n(kn),n(Ws),n(Zn),n(Ns),n(An),n(Vs),n(Rn),n(Xn),n(Fs),n($n),n(Gn),n(zs),n(Bn),n(Wn),n(_),n(Nn),n(Hs),n(Vn),n(k),n(En),n(Ls),n(Fn),n(Ps),n(Qn),n(zn),n(Ks),n(qn),n(Yn),n(sa),n(Hn),n(Sn),n(na),n(Ln),n(Pn),n(la),n(Dn),n(Kn),n(Z),n(On),n(ia),n(st),n(ra),n(at),n(nt),n(ca),n(tt),n(lt),n(ja),n(et),n(da),n(pt),n(it),n(Za)),n(w),m(Q),m(z,s),m(A,s),m(P,s),m(D,s),m(K,s),m(as,s),m(ts,s),m(ls),m(ps,s),m(rs,s),m(js,s),m(ms,s),m(us,s),m(xs,s),m(ys),m(fs,s),m(Js),m(Us,s),m(Cs,s),m(Is),m(_s,s),m(Rs,s),m($s,s),m(Bs,s),m(Es,s),m(Qs,s),m(qs,s),m(Ys),m(Ss),m(Ds,s),m(Os,s),m(aa,s),m(ta,s),m(ea,s),m(pa),m(oa,s),m(ha,s),m(ma,s)}}}const Hl={local:"document-question-answering",sections:[{local:"load-the-data",title:"Load the data"},{local:"preprocess-the-data",sections:[{local:"preprocessing-document-images",title:"Preprocessing document images"},{local:"preprocessing-text-data",title:"Preprocessing text data"}],title:"Preprocess the data"},{local:"evaluation",title:"Evaluation"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Document Question Answering"};function Sl(Aa){return Wl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ae extends Vl{constructor(w){super(),El(this,w,Sl,Yl,Bl,{})}}export{ae as component};
