import{S as ao,i as lo,s as oo,e as o,k as c,w as f,t as i,M as no,c as n,d as s,m,a as r,x as u,h as p,b as h,N as to,G as a,g as l,y as d,q as y,o as M,B as w,v as ro}from"../../chunks/vendor-hf-doc-builder.js";import{T as io}from"../../chunks/Tip-hf-doc-builder.js";import{I as Ie}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as b}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as po}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function co(Ts){let J,C;return{c(){J=o("p"),C=i("Many image captioning datasets contain multiple captions per image. In those cases, a common strategy is to randomly sample a caption amongst the available ones during training.")},l(g){J=n(g,"P",{});var T=r(J);C=p(T,"Many image captioning datasets contain multiple captions per image. In those cases, a common strategy is to randomly sample a caption amongst the available ones during training."),T.forEach(s)},m(g,T){l(g,J,T),a(J,C)},d(g){g&&s(J)}}}function mo(Ts){let J,C,g,T,ss,q,Xt,ts,Vt,Us,L,js,We,Yt,_s,Be,Nt,vs,Z,as,At,Ft,ls,Ht,$s,Ce,Qt,ks,D,Es,Ze,zt,Is,K,Ws,$,G,os,O,St,ns,xt,Bs,R,Pt,ee,qt,Lt,Cs,se,Zs,te,Gs,U,Dt,rs,Kt,Ot,is,ea,sa,Rs,X,Xs,Ge,ta,Vs,ae,Ys,Re,aa,Ns,le,As,oe,Xe,el,Fs,k,V,ps,ne,la,cs,oa,Hs,Ve,na,Qs,Ye,ra,zs,re,Ss,Ne,ia,xs,ie,Ps,Ae,pa,qs,E,Y,ms,pe,ca,hs,ma,Ls,j,ha,ce,fa,ua,me,fs,da,ya,Ds,he,Ks,I,N,us,fe,Ma,ds,wa,Os,_,ba,ue,Ja,ga,de,Ta,Ua,et,A,ja,ye,_a,va,st,Me,tt,W,F,ys,we,$a,Ms,ka,at,H,Ea,Fe,Ia,Wa,lt,Q,Ba,He,Ca,Za,ot,be,nt,Qe,Ga,rt,Je,it,v,Ra,ze,Xa,Va,Se,Ya,Na,pt,ge,ct,xe,Aa,mt,z,Fa,Pe,Ha,Qa,ht,Te,ft,B,S,ws,Ue,za,bs,Sa,ut,x,xa,Js,Pa,qa,dt,je,yt,_e,qe,sl,Mt,ve,wt,P,La,gs,Da,Ka,bt,$e,Jt,ke,gt,Le,Oa,Tt;return q=new Ie({}),L=new po({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/image_captioning.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/image_captioning.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/image_captioning.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/image_captioning.ipynb"}]}}),D=new b({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjAtcSUwQXBpcCUyMGluc3RhbGwlMjBqaXdlciUyMC1x",highlighted:`pip install transformers datasets evaluate -q
pip install jiwer -q`}}),K=new b({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`}}),O=new Ie({}),se=new b({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIybGFtYmRhbGFicyUyRnBva2Vtb24tYmxpcC1jYXB0aW9ucyUyMiklMEFkcw==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

ds = load_dataset(<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>)
ds`}}),te=new b({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2ltYWdlJyUyQyUyMCd0ZXh0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwODMzJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSU3RCk=",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;text&#x27;</span>],
        num_rows: 833
    })
})`}}),X=new io({props:{$$slots:{default:[co]},$$scope:{ctx:Ts}}}),ae=new b({props:{code:"ZHMlMjAlM0QlMjBkcyU1QiUyMnRyYWluJTIyJTVELnRyYWluX3Rlc3Rfc3BsaXQodGVzdF9zaXplJTNEMC4xKSUwQXRyYWluX2RzJTIwJTNEJTIwZHMlNUIlMjJ0cmFpbiUyMiU1RCUwQXRlc3RfZHMlMjAlM0QlMjBkcyU1QiUyMnRlc3QlMjIlNUQ=",highlighted:`ds = ds[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(test_size=<span class="hljs-number">0.1</span>)
train_ds = ds[<span class="hljs-string">&quot;train&quot;</span>]
test_ds = ds[<span class="hljs-string">&quot;test&quot;</span>]`}}),le=new b({props:{code:"ZnJvbSUyMHRleHR3cmFwJTIwaW1wb3J0JTIwd3JhcCUwQWltcG9ydCUyMG1hdHBsb3RsaWIucHlwbG90JTIwYXMlMjBwbHQlMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEElMEElMEFkZWYlMjBwbG90X2ltYWdlcyhpbWFnZXMlMkMlMjBjYXB0aW9ucyklM0ElMEElMjAlMjAlMjAlMjBwbHQuZmlndXJlKGZpZ3NpemUlM0QoMjAlMkMlMjAyMCkpJTBBJTIwJTIwJTIwJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UobGVuKGltYWdlcykpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXglMjAlM0QlMjBwbHQuc3VicGxvdCgxJTJDJTIwbGVuKGltYWdlcyklMkMlMjBpJTIwJTJCJTIwMSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBjYXB0aW9uJTIwJTNEJTIwY2FwdGlvbnMlNUJpJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY2FwdGlvbiUyMCUzRCUyMCUyMiU1Q24lMjIuam9pbih3cmFwKGNhcHRpb24lMkMlMjAxMikpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcGx0LnRpdGxlKGNhcHRpb24pJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcGx0Lmltc2hvdyhpbWFnZXMlNUJpJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBsdC5heGlzKCUyMm9mZiUyMiklMEElMEElMEFzYW1wbGVfaW1hZ2VzX3RvX3Zpc3VhbGl6ZSUyMCUzRCUyMCU1Qm5wLmFycmF5KHRyYWluX2RzJTVCaSU1RCU1QiUyMmltYWdlJTIyJTVEKSUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDUpJTVEJTBBc2FtcGxlX2NhcHRpb25zJTIwJTNEJTIwJTVCdHJhaW5fZHMlNUJpJTVEJTVCJTIydGV4dCUyMiU1RCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDUpJTVEJTBBcGxvdF9pbWFnZXMoc2FtcGxlX2ltYWdlc190b192aXN1YWxpemUlMkMlMjBzYW1wbGVfY2FwdGlvbnMp",highlighted:`<span class="hljs-keyword">from</span> textwrap <span class="hljs-keyword">import</span> wrap
<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">plot_images</span>(<span class="hljs-params">images, captions</span>):
    plt.figure(figsize=(<span class="hljs-number">20</span>, <span class="hljs-number">20</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>(images)):
        ax = plt.subplot(<span class="hljs-number">1</span>, <span class="hljs-built_in">len</span>(images), i + <span class="hljs-number">1</span>)
        caption = captions[i]
        caption = <span class="hljs-string">&quot;\\n&quot;</span>.join(wrap(caption, <span class="hljs-number">12</span>))
        plt.title(caption)
        plt.imshow(images[i])
        plt.axis(<span class="hljs-string">&quot;off&quot;</span>)


sample_images_to_visualize = [np.array(train_ds[i][<span class="hljs-string">&quot;image&quot;</span>]) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>)]
sample_captions = [train_ds[i][<span class="hljs-string">&quot;text&quot;</span>] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>)]
plot_images(sample_images_to_visualize, sample_captions)`}}),ne=new Ie({}),re=new b({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIybWljcm9zb2Z0JTJGZ2l0LWJhc2UlMjIlMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor

checkpoint = <span class="hljs-string">&quot;microsoft/git-base&quot;</span>
processor = AutoProcessor.from_pretrained(checkpoint)`}}),ie=new b({props:{code:"ZGVmJTIwdHJhbnNmb3JtcyhleGFtcGxlX2JhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIyaW1hZ2UlMjIlNUQlNUQlMEElMjAlMjAlMjAlMjBjYXB0aW9ucyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIydGV4dCUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMHByb2Nlc3NvcihpbWFnZXMlM0RpbWFnZXMlMkMlMjB0ZXh0JTNEY2FwdGlvbnMlMkMlMjBwYWRkaW5nJTNEJTIybWF4X2xlbmd0aCUyMiklMEElMjAlMjAlMjAlMjBpbnB1dHMudXBkYXRlKCU3QiUyMmxhYmVscyUyMiUzQSUyMGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCU3RCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHMlMEElMEElMEF0cmFpbl9kcy5zZXRfdHJhbnNmb3JtKHRyYW5zZm9ybXMpJTBBdGVzdF9kcy5zZXRfdHJhbnNmb3JtKHRyYW5zZm9ybXMp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">transforms</span>(<span class="hljs-params">example_batch</span>):
    images = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
    captions = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;text&quot;</span>]]
    inputs = processor(images=images, text=captions, padding=<span class="hljs-string">&quot;max_length&quot;</span>)
    inputs.update({<span class="hljs-string">&quot;labels&quot;</span>: inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]})
    <span class="hljs-keyword">return</span> inputs


train_ds.set_transform(transforms)
test_ds.set_transform(transforms)`}}),pe=new Ie({}),he=new b({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(checkpoint)`}}),fe=new Ie({}),Me=new b({props:{code:"ZnJvbSUyMGV2YWx1YXRlJTIwaW1wb3J0JTIwbG9hZCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBd2VyJTIwJTNEJTIwbG9hZCglMjJ3ZXIlMjIpJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWQlMEElMjAlMjAlMjAlMjBwcmVkaWN0ZWQlMjAlM0QlMjBsb2dpdHMuYXJnbWF4KC0xKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwcHJvY2Vzc29yLmJhdGNoX2RlY29kZShsYWJlbHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjBkZWNvZGVkX3ByZWRpY3Rpb25zJTIwJTNEJTIwcHJvY2Vzc29yLmJhdGNoX2RlY29kZShwcmVkaWN0ZWQlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjB3ZXJfc2NvcmUlMjAlM0QlMjB3ZXIuY29tcHV0ZShwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIyd2VyX3Njb3JlJTIyJTNBJTIwd2VyX3Njb3JlJTdE",highlighted:`<span class="hljs-keyword">from</span> evaluate <span class="hljs-keyword">import</span> load
<span class="hljs-keyword">import</span> torch

wer = load(<span class="hljs-string">&quot;wer&quot;</span>)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
    logits, labels = eval_pred
    predicted = logits.argmax(-<span class="hljs-number">1</span>)
    decoded_labels = processor.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
    decoded_predictions = processor.batch_decode(predicted, skip_special_tokens=<span class="hljs-literal">True</span>)
    wer_score = wer.compute(predictions=decoded_predictions, references=decoded_labels)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;wer_score&quot;</span>: wer_score}`}}),we=new Ie({}),be=new b({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjBjaGVja3BvaW50LnNwbGl0KCUyMiUyRiUyMiklNUIxJTVEJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1wb2tlbW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDVlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDMyJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0QzMiUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3RvdGFsX2xpbWl0JTNEMyUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHJlbW92ZV91bnVzZWRfY29sdW1ucyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWxfbmFtZXMlM0QlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, Trainer

model_name = checkpoint.split(<span class="hljs-string">&quot;/&quot;</span>)[<span class="hljs-number">1</span>]

training_args = TrainingArguments(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-pokemon&quot;</span>,
    learning_rate=<span class="hljs-number">5e-5</span>,
    num_train_epochs=<span class="hljs-number">50</span>,
    fp16=<span class="hljs-literal">True</span>,
    per_device_train_batch_size=<span class="hljs-number">32</span>,
    per_device_eval_batch_size=<span class="hljs-number">32</span>,
    gradient_accumulation_steps=<span class="hljs-number">2</span>,
    save_total_limit=<span class="hljs-number">3</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    eval_steps=<span class="hljs-number">50</span>,
    save_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    save_steps=<span class="hljs-number">50</span>,
    logging_steps=<span class="hljs-number">50</span>,
    remove_unused_columns=<span class="hljs-literal">False</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
    label_names=[<span class="hljs-string">&quot;labels&quot;</span>],
    load_best_model_at_end=<span class="hljs-literal">True</span>,
)`}}),Je=new b({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRyYWluX2RzJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdGVzdF9kcyUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_ds,
    eval_dataset=test_ds,
    compute_metrics=compute_metrics,
)`}}),ge=new b({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()"}}),Te=new b({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()"}}),Ue=new Ie({}),je=new b({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZzYXlha3BhdWwlMkZzYW1wbGUtZGF0YXNldHMlMkZyZXNvbHZlJTJGbWFpbiUyRnBva2Vtb24ucG5nJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBaW1hZ2U=",highlighted:`<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> requests

url = <span class="hljs-string">&quot;https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png&quot;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
image`}}),ve=new b({props:{code:"ZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSUyMGVsc2UlMjAlMjJjcHUlMjIlMEElMEFpbnB1dHMlMjAlM0QlMjBwcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhkZXZpY2UpJTBBcGl4ZWxfdmFsdWVzJTIwJTNEJTIwaW5wdXRzLnBpeGVsX3ZhbHVlcw==",highlighted:`device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)
pixel_values = inputs.pixel_values`}}),$e=new b({props:{code:"Z2VuZXJhdGVkX2lkcyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKHBpeGVsX3ZhbHVlcyUzRHBpeGVsX3ZhbHVlcyUyQyUyMG1heF9sZW5ndGglM0Q1MCklMEFnZW5lcmF0ZWRfY2FwdGlvbiUyMCUzRCUyMHByb2Nlc3Nvci5iYXRjaF9kZWNvZGUoZ2VuZXJhdGVkX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQlMEFwcmludChnZW5lcmF0ZWRfY2FwdGlvbik=",highlighted:`generated_ids = model.generate(pixel_values=pixel_values, max_length=<span class="hljs-number">50</span>)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(generated_caption)`}}),ke=new b({props:{code:"YSUyMGRyYXdpbmclMjBvZiUyMGElMjBwaW5rJTIwYW5kJTIwYmx1ZSUyMHBva2Vtb24=",highlighted:"a drawing of a pink and blue pokemon"}}),{c(){J=o("meta"),C=c(),g=o("h1"),T=o("a"),ss=o("span"),f(q.$$.fragment),Xt=c(),ts=o("span"),Vt=i("Image captioning"),Us=c(),f(L.$$.fragment),js=c(),We=o("p"),Yt=i(`Image captioning is the task of predicting a caption for a given image. Common real world applications of it include
aiding visually impaired people that can help them navigate through different situations. Therefore, image captioning
helps to improve content accessibility for people by describing images to them.`),_s=c(),Be=o("p"),Nt=i("This guide will show you how to:"),vs=c(),Z=o("ul"),as=o("li"),At=i("Fine-tune an image captioning model."),Ft=c(),ls=o("li"),Ht=i("Use the fine-tuned model for inference."),$s=c(),Ce=o("p"),Qt=i("Before you begin, make sure you have all the necessary libraries installed:"),ks=c(),f(D.$$.fragment),Es=c(),Ze=o("p"),zt=i("We encourage you to log in to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to log in:"),Is=c(),f(K.$$.fragment),Ws=c(),$=o("h2"),G=o("a"),os=o("span"),f(O.$$.fragment),St=c(),ns=o("span"),xt=i("Load the Pok\xE9mon BLIP captions dataset"),Bs=c(),R=o("p"),Pt=i(`Use the \u{1F917} Dataset library to load a dataset that consists of {image-caption} pairs. To create your own image captioning dataset
in PyTorch, you can follow `),ee=o("a"),qt=i("this notebook"),Lt=i("."),Cs=c(),f(se.$$.fragment),Zs=c(),f(te.$$.fragment),Gs=c(),U=o("p"),Dt=i("The dataset has two features, "),rs=o("code"),Kt=i("image"),Ot=i(" and "),is=o("code"),ea=i("text"),sa=i("."),Rs=c(),f(X.$$.fragment),Xs=c(),Ge=o("p"),ta=i("Split the dataset\u2019s train split into a train and test set with the [~datasets.Dataset.train_test_split] method:"),Vs=c(),f(ae.$$.fragment),Ys=c(),Re=o("p"),aa=i("Let\u2019s visualize a couple of samples from the training set."),Ns=c(),f(le.$$.fragment),As=c(),oe=o("div"),Xe=o("img"),Fs=c(),k=o("h2"),V=o("a"),ps=o("span"),f(ne.$$.fragment),la=c(),cs=o("span"),oa=i("Preprocess the dataset"),Hs=c(),Ve=o("p"),na=i("Since the dataset has two modalities (image and text), the pre-processing pipeline will preprocess images and the captions."),Qs=c(),Ye=o("p"),ra=i("To do so, load the processor class associated with the model you are about to fine-tune."),zs=c(),f(re.$$.fragment),Ss=c(),Ne=o("p"),ia=i("The processor will internally pre-process the image (which includes resizing, and pixel scaling) and tokenize the caption."),xs=c(),f(ie.$$.fragment),Ps=c(),Ae=o("p"),pa=i("With the dataset ready, you can now set up the model for fine-tuning."),qs=c(),E=o("h2"),Y=o("a"),ms=o("span"),f(pe.$$.fragment),ca=c(),hs=o("span"),ma=i("Load a base model"),Ls=c(),j=o("p"),ha=i("Load the "),ce=o("a"),fa=i("\u201Cmicrosoft/git-base\u201D"),ua=i(" into a "),me=o("a"),fs=o("code"),da=i("AutoModelForCausalLM"),ya=i(" object."),Ds=c(),f(he.$$.fragment),Ks=c(),I=o("h2"),N=o("a"),us=o("span"),f(fe.$$.fragment),Ma=c(),ds=o("span"),wa=i("Evaluate"),Os=c(),_=o("p"),ba=i("Image captioning models are typically evaluated with the "),ue=o("a"),Ja=i("Rouge Score"),ga=i(" or "),de=o("a"),Ta=i("Word Error Rate"),Ua=i(". For this guide, you will use the Word Error Rate (WER)."),et=c(),A=o("p"),ja=i("We use the \u{1F917} Evaluate library to do so. For potential limitations and other gotchas of the WER, refer to "),ye=o("a"),_a=i("this guide"),va=i("."),st=c(),f(Me.$$.fragment),tt=c(),W=o("h2"),F=o("a"),ys=o("span"),f(we.$$.fragment),$a=c(),Ms=o("span"),ka=i("Train!"),at=c(),H=o("p"),Ea=i("Now, you are ready to start fine-tuning the model. You will use the \u{1F917} "),Fe=o("a"),Ia=i("Trainer"),Wa=i(" for this."),lt=c(),Q=o("p"),Ba=i("First, define the training arguments using "),He=o("a"),Ca=i("TrainingArguments"),Za=i("."),ot=c(),f(be.$$.fragment),nt=c(),Qe=o("p"),Ga=i("Then pass them along with the datasets and the model to \u{1F917} Trainer."),rt=c(),f(Je.$$.fragment),it=c(),v=o("p"),Ra=i("To start training, simply call "),ze=o("a"),Xa=i("train()"),Va=i(" on the "),Se=o("a"),Ya=i("Trainer"),Na=i(" object."),pt=c(),f(ge.$$.fragment),ct=c(),xe=o("p"),Aa=i("You should see the training loss drop smoothly as training progresses."),mt=c(),z=o("p"),Fa=i("Once training is completed, share your model to the Hub with the "),Pe=o("a"),Ha=i("push_to_hub()"),Qa=i(" method so everyone can use your model:"),ht=c(),f(Te.$$.fragment),ft=c(),B=o("h2"),S=o("a"),ws=o("span"),f(Ue.$$.fragment),za=c(),bs=o("span"),Sa=i("Inference"),ut=c(),x=o("p"),xa=i("Take a sample image from "),Js=o("code"),Pa=i("test_ds"),qa=i(" to test the model."),dt=c(),f(je.$$.fragment),yt=c(),_e=o("div"),qe=o("img"),Mt=i(`
    
Prepare image for the model.

	`),f(ve.$$.fragment),wt=c(),P=o("p"),La=i("Call "),gs=o("code"),Da=i("generate"),Ka=i(" and decode the predictions."),bt=c(),f($e.$$.fragment),Jt=c(),f(ke.$$.fragment),gt=c(),Le=o("p"),Oa=i("Looks like the fine-tuned model generated a pretty good caption!"),this.h()},l(e){const t=no('[data-svelte="svelte-1phssyn"]',document.head);J=n(t,"META",{name:!0,content:!0}),t.forEach(s),C=m(e),g=n(e,"H1",{class:!0});var Ee=r(g);T=n(Ee,"A",{id:!0,class:!0,href:!0});var tl=r(T);ss=n(tl,"SPAN",{});var al=r(ss);u(q.$$.fragment,al),al.forEach(s),tl.forEach(s),Xt=m(Ee),ts=n(Ee,"SPAN",{});var ll=r(ts);Vt=p(ll,"Image captioning"),ll.forEach(s),Ee.forEach(s),Us=m(e),u(L.$$.fragment,e),js=m(e),We=n(e,"P",{});var ol=r(We);Yt=p(ol,`Image captioning is the task of predicting a caption for a given image. Common real world applications of it include
aiding visually impaired people that can help them navigate through different situations. Therefore, image captioning
helps to improve content accessibility for people by describing images to them.`),ol.forEach(s),_s=m(e),Be=n(e,"P",{});var nl=r(Be);Nt=p(nl,"This guide will show you how to:"),nl.forEach(s),vs=m(e),Z=n(e,"UL",{});var Ut=r(Z);as=n(Ut,"LI",{});var rl=r(as);At=p(rl,"Fine-tune an image captioning model."),rl.forEach(s),Ft=m(Ut),ls=n(Ut,"LI",{});var il=r(ls);Ht=p(il,"Use the fine-tuned model for inference."),il.forEach(s),Ut.forEach(s),$s=m(e),Ce=n(e,"P",{});var pl=r(Ce);Qt=p(pl,"Before you begin, make sure you have all the necessary libraries installed:"),pl.forEach(s),ks=m(e),u(D.$$.fragment,e),Es=m(e),Ze=n(e,"P",{});var cl=r(Ze);zt=p(cl,"We encourage you to log in to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to log in:"),cl.forEach(s),Is=m(e),u(K.$$.fragment,e),Ws=m(e),$=n(e,"H2",{class:!0});var jt=r($);G=n(jt,"A",{id:!0,class:!0,href:!0});var ml=r(G);os=n(ml,"SPAN",{});var hl=r(os);u(O.$$.fragment,hl),hl.forEach(s),ml.forEach(s),St=m(jt),ns=n(jt,"SPAN",{});var fl=r(ns);xt=p(fl,"Load the Pok\xE9mon BLIP captions dataset"),fl.forEach(s),jt.forEach(s),Bs=m(e),R=n(e,"P",{});var _t=r(R);Pt=p(_t,`Use the \u{1F917} Dataset library to load a dataset that consists of {image-caption} pairs. To create your own image captioning dataset
in PyTorch, you can follow `),ee=n(_t,"A",{href:!0,rel:!0});var ul=r(ee);qt=p(ul,"this notebook"),ul.forEach(s),Lt=p(_t,"."),_t.forEach(s),Cs=m(e),u(se.$$.fragment,e),Zs=m(e),u(te.$$.fragment,e),Gs=m(e),U=n(e,"P",{});var De=r(U);Dt=p(De,"The dataset has two features, "),rs=n(De,"CODE",{});var dl=r(rs);Kt=p(dl,"image"),dl.forEach(s),Ot=p(De," and "),is=n(De,"CODE",{});var yl=r(is);ea=p(yl,"text"),yl.forEach(s),sa=p(De,"."),De.forEach(s),Rs=m(e),u(X.$$.fragment,e),Xs=m(e),Ge=n(e,"P",{});var Ml=r(Ge);ta=p(Ml,"Split the dataset\u2019s train split into a train and test set with the [~datasets.Dataset.train_test_split] method:"),Ml.forEach(s),Vs=m(e),u(ae.$$.fragment,e),Ys=m(e),Re=n(e,"P",{});var wl=r(Re);aa=p(wl,"Let\u2019s visualize a couple of samples from the training set."),wl.forEach(s),Ns=m(e),u(le.$$.fragment,e),As=m(e),oe=n(e,"DIV",{class:!0});var bl=r(oe);Xe=n(bl,"IMG",{src:!0,alt:!0}),bl.forEach(s),Fs=m(e),k=n(e,"H2",{class:!0});var vt=r(k);V=n(vt,"A",{id:!0,class:!0,href:!0});var Jl=r(V);ps=n(Jl,"SPAN",{});var gl=r(ps);u(ne.$$.fragment,gl),gl.forEach(s),Jl.forEach(s),la=m(vt),cs=n(vt,"SPAN",{});var Tl=r(cs);oa=p(Tl,"Preprocess the dataset"),Tl.forEach(s),vt.forEach(s),Hs=m(e),Ve=n(e,"P",{});var Ul=r(Ve);na=p(Ul,"Since the dataset has two modalities (image and text), the pre-processing pipeline will preprocess images and the captions."),Ul.forEach(s),Qs=m(e),Ye=n(e,"P",{});var jl=r(Ye);ra=p(jl,"To do so, load the processor class associated with the model you are about to fine-tune."),jl.forEach(s),zs=m(e),u(re.$$.fragment,e),Ss=m(e),Ne=n(e,"P",{});var _l=r(Ne);ia=p(_l,"The processor will internally pre-process the image (which includes resizing, and pixel scaling) and tokenize the caption."),_l.forEach(s),xs=m(e),u(ie.$$.fragment,e),Ps=m(e),Ae=n(e,"P",{});var vl=r(Ae);pa=p(vl,"With the dataset ready, you can now set up the model for fine-tuning."),vl.forEach(s),qs=m(e),E=n(e,"H2",{class:!0});var $t=r(E);Y=n($t,"A",{id:!0,class:!0,href:!0});var $l=r(Y);ms=n($l,"SPAN",{});var kl=r(ms);u(pe.$$.fragment,kl),kl.forEach(s),$l.forEach(s),ca=m($t),hs=n($t,"SPAN",{});var El=r(hs);ma=p(El,"Load a base model"),El.forEach(s),$t.forEach(s),Ls=m(e),j=n(e,"P",{});var Ke=r(j);ha=p(Ke,"Load the "),ce=n(Ke,"A",{href:!0,rel:!0});var Il=r(ce);fa=p(Il,"\u201Cmicrosoft/git-base\u201D"),Il.forEach(s),ua=p(Ke," into a "),me=n(Ke,"A",{href:!0,rel:!0});var Wl=r(me);fs=n(Wl,"CODE",{});var Bl=r(fs);da=p(Bl,"AutoModelForCausalLM"),Bl.forEach(s),Wl.forEach(s),ya=p(Ke," object."),Ke.forEach(s),Ds=m(e),u(he.$$.fragment,e),Ks=m(e),I=n(e,"H2",{class:!0});var kt=r(I);N=n(kt,"A",{id:!0,class:!0,href:!0});var Cl=r(N);us=n(Cl,"SPAN",{});var Zl=r(us);u(fe.$$.fragment,Zl),Zl.forEach(s),Cl.forEach(s),Ma=m(kt),ds=n(kt,"SPAN",{});var Gl=r(ds);wa=p(Gl,"Evaluate"),Gl.forEach(s),kt.forEach(s),Os=m(e),_=n(e,"P",{});var Oe=r(_);ba=p(Oe,"Image captioning models are typically evaluated with the "),ue=n(Oe,"A",{href:!0,rel:!0});var Rl=r(ue);Ja=p(Rl,"Rouge Score"),Rl.forEach(s),ga=p(Oe," or "),de=n(Oe,"A",{href:!0,rel:!0});var Xl=r(de);Ta=p(Xl,"Word Error Rate"),Xl.forEach(s),Ua=p(Oe,". For this guide, you will use the Word Error Rate (WER)."),Oe.forEach(s),et=m(e),A=n(e,"P",{});var Et=r(A);ja=p(Et,"We use the \u{1F917} Evaluate library to do so. For potential limitations and other gotchas of the WER, refer to "),ye=n(Et,"A",{href:!0,rel:!0});var Vl=r(ye);_a=p(Vl,"this guide"),Vl.forEach(s),va=p(Et,"."),Et.forEach(s),st=m(e),u(Me.$$.fragment,e),tt=m(e),W=n(e,"H2",{class:!0});var It=r(W);F=n(It,"A",{id:!0,class:!0,href:!0});var Yl=r(F);ys=n(Yl,"SPAN",{});var Nl=r(ys);u(we.$$.fragment,Nl),Nl.forEach(s),Yl.forEach(s),$a=m(It),Ms=n(It,"SPAN",{});var Al=r(Ms);ka=p(Al,"Train!"),Al.forEach(s),It.forEach(s),at=m(e),H=n(e,"P",{});var Wt=r(H);Ea=p(Wt,"Now, you are ready to start fine-tuning the model. You will use the \u{1F917} "),Fe=n(Wt,"A",{href:!0});var Fl=r(Fe);Ia=p(Fl,"Trainer"),Fl.forEach(s),Wa=p(Wt," for this."),Wt.forEach(s),lt=m(e),Q=n(e,"P",{});var Bt=r(Q);Ba=p(Bt,"First, define the training arguments using "),He=n(Bt,"A",{href:!0});var Hl=r(He);Ca=p(Hl,"TrainingArguments"),Hl.forEach(s),Za=p(Bt,"."),Bt.forEach(s),ot=m(e),u(be.$$.fragment,e),nt=m(e),Qe=n(e,"P",{});var Ql=r(Qe);Ga=p(Ql,"Then pass them along with the datasets and the model to \u{1F917} Trainer."),Ql.forEach(s),rt=m(e),u(Je.$$.fragment,e),it=m(e),v=n(e,"P",{});var es=r(v);Ra=p(es,"To start training, simply call "),ze=n(es,"A",{href:!0});var zl=r(ze);Xa=p(zl,"train()"),zl.forEach(s),Va=p(es," on the "),Se=n(es,"A",{href:!0});var Sl=r(Se);Ya=p(Sl,"Trainer"),Sl.forEach(s),Na=p(es," object."),es.forEach(s),pt=m(e),u(ge.$$.fragment,e),ct=m(e),xe=n(e,"P",{});var xl=r(xe);Aa=p(xl,"You should see the training loss drop smoothly as training progresses."),xl.forEach(s),mt=m(e),z=n(e,"P",{});var Ct=r(z);Fa=p(Ct,"Once training is completed, share your model to the Hub with the "),Pe=n(Ct,"A",{href:!0});var Pl=r(Pe);Ha=p(Pl,"push_to_hub()"),Pl.forEach(s),Qa=p(Ct," method so everyone can use your model:"),Ct.forEach(s),ht=m(e),u(Te.$$.fragment,e),ft=m(e),B=n(e,"H2",{class:!0});var Zt=r(B);S=n(Zt,"A",{id:!0,class:!0,href:!0});var ql=r(S);ws=n(ql,"SPAN",{});var Ll=r(ws);u(Ue.$$.fragment,Ll),Ll.forEach(s),ql.forEach(s),za=m(Zt),bs=n(Zt,"SPAN",{});var Dl=r(bs);Sa=p(Dl,"Inference"),Dl.forEach(s),Zt.forEach(s),ut=m(e),x=n(e,"P",{});var Gt=r(x);xa=p(Gt,"Take a sample image from "),Js=n(Gt,"CODE",{});var Kl=r(Js);Pa=p(Kl,"test_ds"),Kl.forEach(s),qa=p(Gt," to test the model."),Gt.forEach(s),dt=m(e),u(je.$$.fragment,e),yt=m(e),_e=n(e,"DIV",{class:!0});var Ol=r(_e);qe=n(Ol,"IMG",{src:!0,alt:!0}),Ol.forEach(s),Mt=p(e,`
    
Prepare image for the model.

	`),u(ve.$$.fragment,e),wt=m(e),P=n(e,"P",{});var Rt=r(P);La=p(Rt,"Call "),gs=n(Rt,"CODE",{});var eo=r(gs);Da=p(eo,"generate"),eo.forEach(s),Ka=p(Rt," and decode the predictions."),Rt.forEach(s),bt=m(e),u($e.$$.fragment,e),Jt=m(e),u(ke.$$.fragment,e),gt=m(e),Le=n(e,"P",{});var so=r(Le);Oa=p(so,"Looks like the fine-tuned model generated a pretty good caption!"),so.forEach(s),this.h()},h(){h(J,"name","hf:doc:metadata"),h(J,"content",JSON.stringify(ho)),h(T,"id","image-captioning"),h(T,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(T,"href","#image-captioning"),h(g,"class","relative group"),h(G,"id","load-the-pokmon-blip-captions-dataset"),h(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"),h(G,"href","#load-the-pokmon-blip-captions-dataset"),h($,"class","relative group"),h(ee,"href","https://github.com/NielsRogge/Transformers-Tutorials/blob/master/GIT/Fine_tune_GIT_on_an_image_captioning_dataset.ipynb"),h(ee,"rel","nofollow"),to(Xe.src,el="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/sample_training_images_image_cap.png")||h(Xe,"src",el),h(Xe,"alt","Sample training images"),h(oe,"class","flex justify-center"),h(V,"id","preprocess-the-dataset"),h(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"),h(V,"href","#preprocess-the-dataset"),h(k,"class","relative group"),h(Y,"id","load-a-base-model"),h(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"),h(Y,"href","#load-a-base-model"),h(E,"class","relative group"),h(ce,"href","https://huggingface.co/microsoft/git-base"),h(ce,"rel","nofollow"),h(me,"href","https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModelForCausalLM"),h(me,"rel","nofollow"),h(N,"id","evaluate"),h(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"),h(N,"href","#evaluate"),h(I,"class","relative group"),h(ue,"href","https://huggingface.co/spaces/evaluate-metric/rouge"),h(ue,"rel","nofollow"),h(de,"href","https://huggingface.co/spaces/evaluate-metric/wer"),h(de,"rel","nofollow"),h(ye,"href","https://huggingface.co/spaces/evaluate-metric/wer"),h(ye,"rel","nofollow"),h(F,"id","train"),h(F,"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"),h(F,"href","#train"),h(W,"class","relative group"),h(Fe,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),h(He,"href","/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments"),h(ze,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.train"),h(Se,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),h(Pe,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.push_to_hub"),h(S,"id","inference"),h(S,"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"),h(S,"href","#inference"),h(B,"class","relative group"),to(qe.src,sl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/test_image_image_cap.png")||h(qe,"src",sl),h(qe,"alt","Test image"),h(_e,"class","flex justify-center")},m(e,t){a(document.head,J),l(e,C,t),l(e,g,t),a(g,T),a(T,ss),d(q,ss,null),a(g,Xt),a(g,ts),a(ts,Vt),l(e,Us,t),d(L,e,t),l(e,js,t),l(e,We,t),a(We,Yt),l(e,_s,t),l(e,Be,t),a(Be,Nt),l(e,vs,t),l(e,Z,t),a(Z,as),a(as,At),a(Z,Ft),a(Z,ls),a(ls,Ht),l(e,$s,t),l(e,Ce,t),a(Ce,Qt),l(e,ks,t),d(D,e,t),l(e,Es,t),l(e,Ze,t),a(Ze,zt),l(e,Is,t),d(K,e,t),l(e,Ws,t),l(e,$,t),a($,G),a(G,os),d(O,os,null),a($,St),a($,ns),a(ns,xt),l(e,Bs,t),l(e,R,t),a(R,Pt),a(R,ee),a(ee,qt),a(R,Lt),l(e,Cs,t),d(se,e,t),l(e,Zs,t),d(te,e,t),l(e,Gs,t),l(e,U,t),a(U,Dt),a(U,rs),a(rs,Kt),a(U,Ot),a(U,is),a(is,ea),a(U,sa),l(e,Rs,t),d(X,e,t),l(e,Xs,t),l(e,Ge,t),a(Ge,ta),l(e,Vs,t),d(ae,e,t),l(e,Ys,t),l(e,Re,t),a(Re,aa),l(e,Ns,t),d(le,e,t),l(e,As,t),l(e,oe,t),a(oe,Xe),l(e,Fs,t),l(e,k,t),a(k,V),a(V,ps),d(ne,ps,null),a(k,la),a(k,cs),a(cs,oa),l(e,Hs,t),l(e,Ve,t),a(Ve,na),l(e,Qs,t),l(e,Ye,t),a(Ye,ra),l(e,zs,t),d(re,e,t),l(e,Ss,t),l(e,Ne,t),a(Ne,ia),l(e,xs,t),d(ie,e,t),l(e,Ps,t),l(e,Ae,t),a(Ae,pa),l(e,qs,t),l(e,E,t),a(E,Y),a(Y,ms),d(pe,ms,null),a(E,ca),a(E,hs),a(hs,ma),l(e,Ls,t),l(e,j,t),a(j,ha),a(j,ce),a(ce,fa),a(j,ua),a(j,me),a(me,fs),a(fs,da),a(j,ya),l(e,Ds,t),d(he,e,t),l(e,Ks,t),l(e,I,t),a(I,N),a(N,us),d(fe,us,null),a(I,Ma),a(I,ds),a(ds,wa),l(e,Os,t),l(e,_,t),a(_,ba),a(_,ue),a(ue,Ja),a(_,ga),a(_,de),a(de,Ta),a(_,Ua),l(e,et,t),l(e,A,t),a(A,ja),a(A,ye),a(ye,_a),a(A,va),l(e,st,t),d(Me,e,t),l(e,tt,t),l(e,W,t),a(W,F),a(F,ys),d(we,ys,null),a(W,$a),a(W,Ms),a(Ms,ka),l(e,at,t),l(e,H,t),a(H,Ea),a(H,Fe),a(Fe,Ia),a(H,Wa),l(e,lt,t),l(e,Q,t),a(Q,Ba),a(Q,He),a(He,Ca),a(Q,Za),l(e,ot,t),d(be,e,t),l(e,nt,t),l(e,Qe,t),a(Qe,Ga),l(e,rt,t),d(Je,e,t),l(e,it,t),l(e,v,t),a(v,Ra),a(v,ze),a(ze,Xa),a(v,Va),a(v,Se),a(Se,Ya),a(v,Na),l(e,pt,t),d(ge,e,t),l(e,ct,t),l(e,xe,t),a(xe,Aa),l(e,mt,t),l(e,z,t),a(z,Fa),a(z,Pe),a(Pe,Ha),a(z,Qa),l(e,ht,t),d(Te,e,t),l(e,ft,t),l(e,B,t),a(B,S),a(S,ws),d(Ue,ws,null),a(B,za),a(B,bs),a(bs,Sa),l(e,ut,t),l(e,x,t),a(x,xa),a(x,Js),a(Js,Pa),a(x,qa),l(e,dt,t),d(je,e,t),l(e,yt,t),l(e,_e,t),a(_e,qe),l(e,Mt,t),d(ve,e,t),l(e,wt,t),l(e,P,t),a(P,La),a(P,gs),a(gs,Da),a(P,Ka),l(e,bt,t),d($e,e,t),l(e,Jt,t),d(ke,e,t),l(e,gt,t),l(e,Le,t),a(Le,Oa),Tt=!0},p(e,[t]){const Ee={};t&2&&(Ee.$$scope={dirty:t,ctx:e}),X.$set(Ee)},i(e){Tt||(y(q.$$.fragment,e),y(L.$$.fragment,e),y(D.$$.fragment,e),y(K.$$.fragment,e),y(O.$$.fragment,e),y(se.$$.fragment,e),y(te.$$.fragment,e),y(X.$$.fragment,e),y(ae.$$.fragment,e),y(le.$$.fragment,e),y(ne.$$.fragment,e),y(re.$$.fragment,e),y(ie.$$.fragment,e),y(pe.$$.fragment,e),y(he.$$.fragment,e),y(fe.$$.fragment,e),y(Me.$$.fragment,e),y(we.$$.fragment,e),y(be.$$.fragment,e),y(Je.$$.fragment,e),y(ge.$$.fragment,e),y(Te.$$.fragment,e),y(Ue.$$.fragment,e),y(je.$$.fragment,e),y(ve.$$.fragment,e),y($e.$$.fragment,e),y(ke.$$.fragment,e),Tt=!0)},o(e){M(q.$$.fragment,e),M(L.$$.fragment,e),M(D.$$.fragment,e),M(K.$$.fragment,e),M(O.$$.fragment,e),M(se.$$.fragment,e),M(te.$$.fragment,e),M(X.$$.fragment,e),M(ae.$$.fragment,e),M(le.$$.fragment,e),M(ne.$$.fragment,e),M(re.$$.fragment,e),M(ie.$$.fragment,e),M(pe.$$.fragment,e),M(he.$$.fragment,e),M(fe.$$.fragment,e),M(Me.$$.fragment,e),M(we.$$.fragment,e),M(be.$$.fragment,e),M(Je.$$.fragment,e),M(ge.$$.fragment,e),M(Te.$$.fragment,e),M(Ue.$$.fragment,e),M(je.$$.fragment,e),M(ve.$$.fragment,e),M($e.$$.fragment,e),M(ke.$$.fragment,e),Tt=!1},d(e){s(J),e&&s(C),e&&s(g),w(q),e&&s(Us),w(L,e),e&&s(js),e&&s(We),e&&s(_s),e&&s(Be),e&&s(vs),e&&s(Z),e&&s($s),e&&s(Ce),e&&s(ks),w(D,e),e&&s(Es),e&&s(Ze),e&&s(Is),w(K,e),e&&s(Ws),e&&s($),w(O),e&&s(Bs),e&&s(R),e&&s(Cs),w(se,e),e&&s(Zs),w(te,e),e&&s(Gs),e&&s(U),e&&s(Rs),w(X,e),e&&s(Xs),e&&s(Ge),e&&s(Vs),w(ae,e),e&&s(Ys),e&&s(Re),e&&s(Ns),w(le,e),e&&s(As),e&&s(oe),e&&s(Fs),e&&s(k),w(ne),e&&s(Hs),e&&s(Ve),e&&s(Qs),e&&s(Ye),e&&s(zs),w(re,e),e&&s(Ss),e&&s(Ne),e&&s(xs),w(ie,e),e&&s(Ps),e&&s(Ae),e&&s(qs),e&&s(E),w(pe),e&&s(Ls),e&&s(j),e&&s(Ds),w(he,e),e&&s(Ks),e&&s(I),w(fe),e&&s(Os),e&&s(_),e&&s(et),e&&s(A),e&&s(st),w(Me,e),e&&s(tt),e&&s(W),w(we),e&&s(at),e&&s(H),e&&s(lt),e&&s(Q),e&&s(ot),w(be,e),e&&s(nt),e&&s(Qe),e&&s(rt),w(Je,e),e&&s(it),e&&s(v),e&&s(pt),w(ge,e),e&&s(ct),e&&s(xe),e&&s(mt),e&&s(z),e&&s(ht),w(Te,e),e&&s(ft),e&&s(B),w(Ue),e&&s(ut),e&&s(x),e&&s(dt),w(je,e),e&&s(yt),e&&s(_e),e&&s(Mt),w(ve,e),e&&s(wt),e&&s(P),e&&s(bt),w($e,e),e&&s(Jt),w(ke,e),e&&s(gt),e&&s(Le)}}}const ho={local:"image-captioning",sections:[{local:"load-the-pokmon-blip-captions-dataset",title:"Load the Pok\xE9mon BLIP captions dataset"},{local:"preprocess-the-dataset",title:"Preprocess the dataset"},{local:"load-a-base-model",title:"Load a base model"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train!"},{local:"inference",title:"Inference"}],title:"Image captioning"};function fo(Ts){return ro(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Jo extends ao{constructor(J){super();lo(this,J,fo,mo,oo,{})}}export{Jo as default,ho as metadata};
