import{S as lo,i as ao,s as oo,e as o,k as c,w as f,t as i,M as ro,c as r,d as s,m,a as n,x as u,h as p,b as h,N as to,G as l,g as a,y as d,q as y,o as M,B as w,v as no}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=r(g,"P",{});var T=n(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){a(g,J,T),l(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,vs,Be,Nt,_s,Z,ls,At,Ft,as,Ht,$s,Ce,Qt,ks,D,Es,Ze,zt,Is,K,Ws,$,G,os,O,St,rs,xt,Bs,R,Pt,ee,qt,Lt,Cs,se,Zs,te,Gs,U,Dt,ns,Kt,Ot,is,el,sl,Rs,X,Xs,Ge,tl,Vs,le,Ys,Re,ll,Ns,ae,As,oe,Xe,ea,Fs,k,V,ps,re,al,cs,ol,Hs,Ve,rl,Qs,Ye,nl,zs,ne,Ss,Ne,il,xs,ie,Ps,Ae,pl,qs,E,Y,ms,pe,cl,hs,ml,Ls,j,hl,ce,fl,ul,me,fs,dl,yl,Ds,he,Ks,I,N,us,fe,Ml,ds,wl,Os,v,bl,ue,Jl,gl,de,Tl,Ul,et,A,jl,ye,vl,_l,st,Me,tt,W,F,ys,we,$l,Ms,kl,lt,H,El,Fe,Il,Wl,at,Q,Bl,He,Cl,Zl,ot,be,rt,Qe,Gl,nt,Je,it,_,Rl,ze,Xl,Vl,Se,Yl,Nl,pt,ge,ct,xe,Al,mt,z,Fl,Pe,Hl,Ql,ht,Te,ft,B,S,ws,Ue,zl,bs,Sl,ut,x,xl,Js,Pl,ql,dt,je,yt,ve,qe,sa,Mt,_e,wt,P,Ll,gs,Dl,Kl,bt,$e,Jt,ke,gt,Le,Ol,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}}}),le=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>]`}}),ae=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)`}}),re=new Ie({}),ne=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`}}),_e=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.`),vs=c(),Be=o("p"),Nt=i("This guide will show you how to:"),_s=c(),Z=o("ul"),ls=o("li"),At=i("Fine-tune an image captioning model."),Ft=c(),as=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(),rs=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, "),ns=o("code"),Kt=i("image"),Ot=i(" and "),is=o("code"),el=i("text"),sl=i("."),Rs=c(),f(X.$$.fragment),Xs=c(),Ge=o("p"),tl=i("Split the dataset\u2019s train split into a train and test set with the [~datasets.Dataset.train_test_split] method:"),Vs=c(),f(le.$$.fragment),Ys=c(),Re=o("p"),ll=i("Let\u2019s visualize a couple of samples from the training set."),Ns=c(),f(ae.$$.fragment),As=c(),oe=o("div"),Xe=o("img"),Fs=c(),k=o("h2"),V=o("a"),ps=o("span"),f(re.$$.fragment),al=c(),cs=o("span"),ol=i("Preprocess the dataset"),Hs=c(),Ve=o("p"),rl=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"),nl=i("To do so, load the processor class associated with the model you are about to fine-tune."),zs=c(),f(ne.$$.fragment),Ss=c(),Ne=o("p"),il=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"),pl=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),cl=c(),hs=o("span"),ml=i("Load a base model"),Ls=c(),j=o("p"),hl=i("Load the "),ce=o("a"),fl=i("\u201Cmicrosoft/git-base\u201D"),ul=i(" into a "),me=o("a"),fs=o("code"),dl=i("AutoModelForCausalLM"),yl=i(" object."),Ds=c(),f(he.$$.fragment),Ks=c(),I=o("h2"),N=o("a"),us=o("span"),f(fe.$$.fragment),Ml=c(),ds=o("span"),wl=i("Evaluate"),Os=c(),v=o("p"),bl=i("Image captioning models are typically evaluated with the "),ue=o("a"),Jl=i("Rouge Score"),gl=i(" or "),de=o("a"),Tl=i("Word Error Rate"),Ul=i(". For this guide, you will use the Word Error Rate (WER)."),et=c(),A=o("p"),jl=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"),vl=i("this guide"),_l=i("."),st=c(),f(Me.$$.fragment),tt=c(),W=o("h2"),F=o("a"),ys=o("span"),f(we.$$.fragment),$l=c(),Ms=o("span"),kl=i("Train!"),lt=c(),H=o("p"),El=i("Now, you are ready to start fine-tuning the model. You will use the \u{1F917} "),Fe=o("a"),Il=i("Trainer"),Wl=i(" for this."),at=c(),Q=o("p"),Bl=i("First, define the training arguments using "),He=o("a"),Cl=i("TrainingArguments"),Zl=i("."),ot=c(),f(be.$$.fragment),rt=c(),Qe=o("p"),Gl=i("Then pass them along with the datasets and the model to \u{1F917} Trainer."),nt=c(),f(Je.$$.fragment),it=c(),_=o("p"),Rl=i("To start training, simply call "),ze=o("a"),Xl=i("train()"),Vl=i(" on the "),Se=o("a"),Yl=i("Trainer"),Nl=i(" object."),pt=c(),f(ge.$$.fragment),ct=c(),xe=o("p"),Al=i("You should see the training loss drop smoothly as training progresses."),mt=c(),z=o("p"),Fl=i("Once training is completed, share your model to the Hub with the "),Pe=o("a"),Hl=i("push_to_hub()"),Ql=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),zl=c(),bs=o("span"),Sl=i("Inference"),ut=c(),x=o("p"),xl=i("Take a sample image from "),Js=o("code"),Pl=i("test_ds"),ql=i(" to test the model."),dt=c(),f(je.$$.fragment),yt=c(),ve=o("div"),qe=o("img"),Mt=i(`
    
Prepare image for the model.

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

	`),u(_e.$$.fragment,e),wt=m(e),P=r(e,"P",{});var Rt=n(P);Ll=p(Rt,"Call "),gs=r(Rt,"CODE",{});var eo=n(gs);Dl=p(eo,"generate"),eo.forEach(s),Kl=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=r(e,"P",{});var so=n(Le);Ol=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,ea="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/sample_training_images_image_cap.png")||h(Xe,"src",ea),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/v4.32.0/en/main_classes/trainer#transformers.Trainer"),h(He,"href","/docs/transformers/v4.32.0/en/main_classes/trainer#transformers.TrainingArguments"),h(ze,"href","/docs/transformers/v4.32.0/en/main_classes/trainer#transformers.Trainer.train"),h(Se,"href","/docs/transformers/v4.32.0/en/main_classes/trainer#transformers.Trainer"),h(Pe,"href","/docs/transformers/v4.32.0/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,sa="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/test_image_image_cap.png")||h(qe,"src",sa),h(qe,"alt","Test image"),h(ve,"class","flex justify-center")},m(e,t){l(document.head,J),a(e,C,t),a(e,g,t),l(g,T),l(T,ss),d(q,ss,null),l(g,Xt),l(g,ts),l(ts,Vt),a(e,Us,t),d(L,e,t),a(e,js,t),a(e,We,t),l(We,Yt),a(e,vs,t),a(e,Be,t),l(Be,Nt),a(e,_s,t),a(e,Z,t),l(Z,ls),l(ls,At),l(Z,Ft),l(Z,as),l(as,Ht),a(e,$s,t),a(e,Ce,t),l(Ce,Qt),a(e,ks,t),d(D,e,t),a(e,Es,t),a(e,Ze,t),l(Ze,zt),a(e,Is,t),d(K,e,t),a(e,Ws,t),a(e,$,t),l($,G),l(G,os),d(O,os,null),l($,St),l($,rs),l(rs,xt),a(e,Bs,t),a(e,R,t),l(R,Pt),l(R,ee),l(ee,qt),l(R,Lt),a(e,Cs,t),d(se,e,t),a(e,Zs,t),d(te,e,t),a(e,Gs,t),a(e,U,t),l(U,Dt),l(U,ns),l(ns,Kt),l(U,Ot),l(U,is),l(is,el),l(U,sl),a(e,Rs,t),d(X,e,t),a(e,Xs,t),a(e,Ge,t),l(Ge,tl),a(e,Vs,t),d(le,e,t),a(e,Ys,t),a(e,Re,t),l(Re,ll),a(e,Ns,t),d(ae,e,t),a(e,As,t),a(e,oe,t),l(oe,Xe),a(e,Fs,t),a(e,k,t),l(k,V),l(V,ps),d(re,ps,null),l(k,al),l(k,cs),l(cs,ol),a(e,Hs,t),a(e,Ve,t),l(Ve,rl),a(e,Qs,t),a(e,Ye,t),l(Ye,nl),a(e,zs,t),d(ne,e,t),a(e,Ss,t),a(e,Ne,t),l(Ne,il),a(e,xs,t),d(ie,e,t),a(e,Ps,t),a(e,Ae,t),l(Ae,pl),a(e,qs,t),a(e,E,t),l(E,Y),l(Y,ms),d(pe,ms,null),l(E,cl),l(E,hs),l(hs,ml),a(e,Ls,t),a(e,j,t),l(j,hl),l(j,ce),l(ce,fl),l(j,ul),l(j,me),l(me,fs),l(fs,dl),l(j,yl),a(e,Ds,t),d(he,e,t),a(e,Ks,t),a(e,I,t),l(I,N),l(N,us),d(fe,us,null),l(I,Ml),l(I,ds),l(ds,wl),a(e,Os,t),a(e,v,t),l(v,bl),l(v,ue),l(ue,Jl),l(v,gl),l(v,de),l(de,Tl),l(v,Ul),a(e,et,t),a(e,A,t),l(A,jl),l(A,ye),l(ye,vl),l(A,_l),a(e,st,t),d(Me,e,t),a(e,tt,t),a(e,W,t),l(W,F),l(F,ys),d(we,ys,null),l(W,$l),l(W,Ms),l(Ms,kl),a(e,lt,t),a(e,H,t),l(H,El),l(H,Fe),l(Fe,Il),l(H,Wl),a(e,at,t),a(e,Q,t),l(Q,Bl),l(Q,He),l(He,Cl),l(Q,Zl),a(e,ot,t),d(be,e,t),a(e,rt,t),a(e,Qe,t),l(Qe,Gl),a(e,nt,t),d(Je,e,t),a(e,it,t),a(e,_,t),l(_,Rl),l(_,ze),l(ze,Xl),l(_,Vl),l(_,Se),l(Se,Yl),l(_,Nl),a(e,pt,t),d(ge,e,t),a(e,ct,t),a(e,xe,t),l(xe,Al),a(e,mt,t),a(e,z,t),l(z,Fl),l(z,Pe),l(Pe,Hl),l(z,Ql),a(e,ht,t),d(Te,e,t),a(e,ft,t),a(e,B,t),l(B,S),l(S,ws),d(Ue,ws,null),l(B,zl),l(B,bs),l(bs,Sl),a(e,ut,t),a(e,x,t),l(x,xl),l(x,Js),l(Js,Pl),l(x,ql),a(e,dt,t),d(je,e,t),a(e,yt,t),a(e,ve,t),l(ve,qe),a(e,Mt,t),d(_e,e,t),a(e,wt,t),a(e,P,t),l(P,Ll),l(P,gs),l(gs,Dl),l(P,Kl),a(e,bt,t),d($e,e,t),a(e,Jt,t),d(ke,e,t),a(e,gt,t),a(e,Le,t),l(Le,Ol),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(le.$$.fragment,e),y(ae.$$.fragment,e),y(re.$$.fragment,e),y(ne.$$.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(_e.$$.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(le.$$.fragment,e),M(ae.$$.fragment,e),M(re.$$.fragment,e),M(ne.$$.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(_e.$$.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(vs),e&&s(Be),e&&s(_s),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(le,e),e&&s(Ys),e&&s(Re),e&&s(Ns),w(ae,e),e&&s(As),e&&s(oe),e&&s(Fs),e&&s(k),w(re),e&&s(Hs),e&&s(Ve),e&&s(Qs),e&&s(Ye),e&&s(zs),w(ne,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(v),e&&s(et),e&&s(A),e&&s(st),w(Me,e),e&&s(tt),e&&s(W),w(we),e&&s(lt),e&&s(H),e&&s(at),e&&s(Q),e&&s(ot),w(be,e),e&&s(rt),e&&s(Qe),e&&s(nt),w(Je,e),e&&s(it),e&&s(_),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(ve),e&&s(Mt),w(_e,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 no(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Jo extends lo{constructor(J){super();ao(this,J,fo,mo,oo,{})}}export{Jo as default,ho as metadata};
