import{s as il,o as rl,n as Ml}from"../chunks/scheduler.9bc65507.js";import{S as ml,i as ol,g as p,s as a,r,A as cl,h as i,f as l,c as n,j as pl,u as M,x as d,k as Bt,y as yl,a as s,v as m,d as o,t as c,w as y}from"../chunks/index.707bf1b6.js";import{T as dl}from"../chunks/Tip.c2ecdbf4.js";import{C as f}from"../chunks/CodeBlock.54a9f38d.js";import{D as fl}from"../chunks/DocNotebookDropdown.41f65cb5.js";import{H as Ue,E as wl}from"../chunks/EditOnGithub.922df6ba.js";function ul($e){let w,h="多くの画像キャプション データセットには、画像ごとに複数のキャプションが含まれています。このような場合、一般的な戦略は、トレーニング中に利用可能なキャプションの中からランダムにキャプションをサンプリングすることです。";return{c(){w=p("p"),w.textContent=h},l(u){w=i(u,"P",{"data-svelte-h":!0}),d(w)!=="svelte-6nosxd"&&(w.textContent=h)},m(u,je){s(u,w,je)},p:Ml,d(u){u&&l(w)}}}function Jl($e){let w,h,u,je,U,Ce,j,_e,g,Wt=`画像のキャプション付けは、特定の画像のキャプションを予測するタスクです。一般的な現実世界のアプリケーションには次のものがあります。
視覚障害者がさまざまな状況を乗り越えられるよう支援します。したがって、画像のキャプション
画像を説明することで人々のコンテンツへのアクセシビリティを向上させるのに役立ちます。`,ke,$,It="このガイドでは、次の方法を説明します。",ve,C,Zt="<li>画像キャプション モデルを微調整します。</li> <li>微調整されたモデルを推論に使用します。</li>",Be,_,Gt="始める前に、必要なライブラリがすべてインストールされていることを確認してください。",We,k,Ie,v,xt="モデルをアップロードしてコミュニティと共有できるように、Hugging Face アカウントにログインすることをお勧めします。プロンプトが表示されたら、トークンを入力してログインします。",Ze,B,Ge,W,xe,I,Rt=`🤗 データセット ライブラリを使用して、{image-caption} ペアで構成されるデータセットを読み込みます。独自の画像キャプション データセットを作成するには
PyTorch では、<a href="https://github.com/NielsRogge/Transformers-Tutorials/blob/master/GIT/Fine_tune_GIT_on_an_image_captioning_dataset.ipynb" rel="nofollow">このノートブック</a> を参照できます。`,Re,Z,Xe,G,He,x,Xt="データセットには <code>image</code>と<code>text</code>の 2 つの機能があります。",Ve,J,Ye,R,Ht="<code>train_test_split</code> メソッドを使用して、データセットのトレイン スプリットをトレイン セットとテスト セットに分割します。",Ee,X,Qe,H,Vt="トレーニング セットからのいくつかのサンプルを視覚化してみましょう。",Ne,V,ze,b,Yt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/sample_training_images_image_cap.png" alt="Sample training images"/>',Fe,Y,Ae,E,Et="データセットには 2 つのモダリティ (画像とテキスト) があるため、前処理パイプラインは画像とキャプションを前処理します。",Se,Q,Qt="これを行うには、微調整しようとしているモデルに関連付けられたプロセッサ クラスをロードします。",qe,N,Le,z,Nt="プロセッサは内部で画像を前処理し (サイズ変更やピクセル スケーリングを含む)、キャプションをトークン化します。",Pe,F,Ke,A,zt="データセットの準備ができたら、微調整用にモデルをセットアップできます。",De,S,Oe,q,Ft='<a href="https://huggingface.co/microsoft/git-base" rel="nofollow">“microsoft/git-base”</a> を <a href="https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModelForCausalLM" rel="nofollow"><code>AutoModelForCausalLM</code></a> オブジェクト。',et,L,tt,P,lt,K,st,D,At='画像キャプション モデルは通常、<a href="https://huggingface.co/spaces/evaluate-metric/rouge" rel="nofollow">Rouge Score</a> または <a href="https://huggingface.co/spaces/evaluate-metric/" rel="nofollow">Word Error Rate</a> で評価されます。そうだった）。このガイドでは、Word Error Rate (WER) を使用します。',at,O,St='これを行うには 🤗 Evaluate ライブラリを使用します。 WER の潜在的な制限やその他の問題点については、<a href="https://huggingface.co/spaces/evaluate-metric/wer" rel="nofollow">このガイド</a> を参照してください。',nt,ee,pt,te,it,le,qt='これで、モデルの微調整を開始する準備が整いました。これには 🤗 <a href="/docs/transformers/v4.41.2/ja/main_classes/trainer#transformers.Trainer">Trainer</a> を使用します。',rt,se,Lt='まず、<a href="/docs/transformers/v4.41.2/ja/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> を使用してトレーニング引数を定義します。',Mt,ae,mt,ne,Pt="Trainer 次に、次に、データセットとモデルと一緒に 🤗 に渡します。",ot,pe,ct,ie,Kt='トレーニングを開始するには、<a href="/docs/transformers/v4.41.2/ja/main_classes/trainer#transformers.Trainer">Trainer</a> オブジェクトの <a href="/docs/transformers/v4.41.2/ja/main_classes/trainer#transformers.Trainer.train">train()</a> を呼び出すだけです。',yt,re,dt,Me,Dt="トレーニングが進むにつれて、トレーニングの損失がスムーズに減少することがわかります。",ft,me,Ot='トレーニングが完了したら、 <a href="/docs/transformers/v4.41.2/ja/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> メソッドを使用してモデルをハブに共有し、誰もがモデルを使用できるようにします。',wt,oe,ut,ce,Jt,ye,el="<code>test_ds</code> からサンプル画像を取得してモデルをテストします。",bt,de,Tt,T,tl='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/test_image_image_cap.png" alt="Test image"/>',ht,fe,ll="モデル用の画像を準備します。",Ut,we,jt,ue,sl="<code>generate</code> を呼び出して予測をデコードします。",gt,Je,$t,be,Ct,Te,al="微調整されたモデルにより、非常に優れたキャプションが生成されたようです。",_t,he,kt,ge,vt;return U=new Ue({props:{title:"Image captioning",local:"image-captioning",headingTag:"h1"}}),j=new fl({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/ja/image_captioning.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ja/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ja/tensorflow/image_captioning.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ja/image_captioning.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ja/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ja/tensorflow/image_captioning.ipynb"}]}}),k=new f({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjAtcSUwQXBpcCUyMGluc3RhbGwlMjBqaXdlciUyMC1x",highlighted:`pip install transformers datasets evaluate -q
pip install jiwer -q`,wrap:!1}}),B=new f({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),W=new Ue({props:{title:"Load the Pokémon BLIP captions dataset",local:"load-the-pokémon-blip-captions-dataset",headingTag:"h2"}}),Z=new f({props:{code:"ZHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIybGFtYmRhbGFicyUyRnBva2Vtb24tYmxpcC1jYXB0aW9ucyUyMiklMEFkcw==",highlighted:`ds = load_dataset(<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>)
ds`,wrap:!1}}),G=new f({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
    })
})`,wrap:!1}}),J=new dl({props:{$$slots:{default:[ul]},$$scope:{ctx:$e}}}),X=new f({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>]`,wrap:!1}}),V=new f({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)`,wrap:!1}}),Y=new Ue({props:{title:"Preprocess the dataset",local:"preprocess-the-dataset",headingTag:"h2"}}),N=new f({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)`,wrap:!1}}),F=new f({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)`,wrap:!1}}),S=new Ue({props:{title:"Load a base model",local:"load-a-base-model",headingTag:"h2"}}),L=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(checkpoint)`,wrap:!1}}),P=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(checkpoint)`,wrap:!1}}),K=new Ue({props:{title:"Evaluate",local:"evaluate",headingTag:"h2"}}),ee=new f({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}`,wrap:!1}}),te=new Ue({props:{title:"Train!",local:"train",headingTag:"h2"}}),ae=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjBjaGVja3BvaW50LnNwbGl0KCUyMiUyRiUyMiklNUIxJTVEJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1wb2tlbW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDVlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDMyJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0QzMiUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3RvdGFsX2xpbWl0JTNEMyUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHJlbW92ZV91bnVzZWRfY29sdW1ucyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWxfbmFtZXMlM0QlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSk=",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>,
    eval_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>,
)`,wrap:!1}}),pe=new f({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRyYWluX2RzJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdGVzdF9kcyUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_ds,
    eval_dataset=test_ds,
    compute_metrics=compute_metrics,
)`,wrap:!1}}),re=new f({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),oe=new f({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),ce=new Ue({props:{title:"Inference",local:"inference",headingTag:"h2"}}),de=new f({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`,wrap:!1}}),we=new f({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`,wrap:!1}}),Je=new f({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)`,wrap:!1}}),be=new f({props:{code:"YSUyMGRyYXdpbmclMjBvZiUyMGElMjBwaW5rJTIwYW5kJTIwYmx1ZSUyMHBva2Vtb24=",highlighted:"a drawing of a pink and blue pokemon",wrap:!1}}),he=new wl({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ja/tasks/image_captioning.md"}}),{c(){w=p("meta"),h=a(),u=p("p"),je=a(),r(U.$$.fragment),Ce=a(),r(j.$$.fragment),_e=a(),g=p("p"),g.textContent=Wt,ke=a(),$=p("p"),$.textContent=It,ve=a(),C=p("ul"),C.innerHTML=Zt,Be=a(),_=p("p"),_.textContent=Gt,We=a(),r(k.$$.fragment),Ie=a(),v=p("p"),v.textContent=xt,Ze=a(),r(B.$$.fragment),Ge=a(),r(W.$$.fragment),xe=a(),I=p("p"),I.innerHTML=Rt,Re=a(),r(Z.$$.fragment),Xe=a(),r(G.$$.fragment),He=a(),x=p("p"),x.innerHTML=Xt,Ve=a(),r(J.$$.fragment),Ye=a(),R=p("p"),R.innerHTML=Ht,Ee=a(),r(X.$$.fragment),Qe=a(),H=p("p"),H.textContent=Vt,Ne=a(),r(V.$$.fragment),ze=a(),b=p("div"),b.innerHTML=Yt,Fe=a(),r(Y.$$.fragment),Ae=a(),E=p("p"),E.textContent=Et,Se=a(),Q=p("p"),Q.textContent=Qt,qe=a(),r(N.$$.fragment),Le=a(),z=p("p"),z.textContent=Nt,Pe=a(),r(F.$$.fragment),Ke=a(),A=p("p"),A.textContent=zt,De=a(),r(S.$$.fragment),Oe=a(),q=p("p"),q.innerHTML=Ft,et=a(),r(L.$$.fragment),tt=a(),r(P.$$.fragment),lt=a(),r(K.$$.fragment),st=a(),D=p("p"),D.innerHTML=At,at=a(),O=p("p"),O.innerHTML=St,nt=a(),r(ee.$$.fragment),pt=a(),r(te.$$.fragment),it=a(),le=p("p"),le.innerHTML=qt,rt=a(),se=p("p"),se.innerHTML=Lt,Mt=a(),r(ae.$$.fragment),mt=a(),ne=p("p"),ne.textContent=Pt,ot=a(),r(pe.$$.fragment),ct=a(),ie=p("p"),ie.innerHTML=Kt,yt=a(),r(re.$$.fragment),dt=a(),Me=p("p"),Me.textContent=Dt,ft=a(),me=p("p"),me.innerHTML=Ot,wt=a(),r(oe.$$.fragment),ut=a(),r(ce.$$.fragment),Jt=a(),ye=p("p"),ye.innerHTML=el,bt=a(),r(de.$$.fragment),Tt=a(),T=p("div"),T.innerHTML=tl,ht=a(),fe=p("p"),fe.textContent=ll,Ut=a(),r(we.$$.fragment),jt=a(),ue=p("p"),ue.innerHTML=sl,gt=a(),r(Je.$$.fragment),$t=a(),r(be.$$.fragment),Ct=a(),Te=p("p"),Te.textContent=al,_t=a(),r(he.$$.fragment),kt=a(),ge=p("p"),this.h()},l(e){const t=cl("svelte-u9bgzb",document.head);w=i(t,"META",{name:!0,content:!0}),t.forEach(l),h=n(e),u=i(e,"P",{}),pl(u).forEach(l),je=n(e),M(U.$$.fragment,e),Ce=n(e),M(j.$$.fragment,e),_e=n(e),g=i(e,"P",{"data-svelte-h":!0}),d(g)!=="svelte-1p0rp9p"&&(g.textContent=Wt),ke=n(e),$=i(e,"P",{"data-svelte-h":!0}),d($)!=="svelte-w5jzhi"&&($.textContent=It),ve=n(e),C=i(e,"UL",{"data-svelte-h":!0}),d(C)!=="svelte-9iba6s"&&(C.innerHTML=Zt),Be=n(e),_=i(e,"P",{"data-svelte-h":!0}),d(_)!=="svelte-1lya3k8"&&(_.textContent=Gt),We=n(e),M(k.$$.fragment,e),Ie=n(e),v=i(e,"P",{"data-svelte-h":!0}),d(v)!=="svelte-193zy02"&&(v.textContent=xt),Ze=n(e),M(B.$$.fragment,e),Ge=n(e),M(W.$$.fragment,e),xe=n(e),I=i(e,"P",{"data-svelte-h":!0}),d(I)!=="svelte-qgn9jw"&&(I.innerHTML=Rt),Re=n(e),M(Z.$$.fragment,e),Xe=n(e),M(G.$$.fragment,e),He=n(e),x=i(e,"P",{"data-svelte-h":!0}),d(x)!=="svelte-yyzvcj"&&(x.innerHTML=Xt),Ve=n(e),M(J.$$.fragment,e),Ye=n(e),R=i(e,"P",{"data-svelte-h":!0}),d(R)!=="svelte-jq14pt"&&(R.innerHTML=Ht),Ee=n(e),M(X.$$.fragment,e),Qe=n(e),H=i(e,"P",{"data-svelte-h":!0}),d(H)!=="svelte-80oyiw"&&(H.textContent=Vt),Ne=n(e),M(V.$$.fragment,e),ze=n(e),b=i(e,"DIV",{class:!0,"data-svelte-h":!0}),d(b)!=="svelte-1qemygy"&&(b.innerHTML=Yt),Fe=n(e),M(Y.$$.fragment,e),Ae=n(e),E=i(e,"P",{"data-svelte-h":!0}),d(E)!=="svelte-xo16vn"&&(E.textContent=Et),Se=n(e),Q=i(e,"P",{"data-svelte-h":!0}),d(Q)!=="svelte-sn04hr"&&(Q.textContent=Qt),qe=n(e),M(N.$$.fragment,e),Le=n(e),z=i(e,"P",{"data-svelte-h":!0}),d(z)!=="svelte-d4wa2b"&&(z.textContent=Nt),Pe=n(e),M(F.$$.fragment,e),Ke=n(e),A=i(e,"P",{"data-svelte-h":!0}),d(A)!=="svelte-13xhvmf"&&(A.textContent=zt),De=n(e),M(S.$$.fragment,e),Oe=n(e),q=i(e,"P",{"data-svelte-h":!0}),d(q)!=="svelte-10063ke"&&(q.innerHTML=Ft),et=n(e),M(L.$$.fragment,e),tt=n(e),M(P.$$.fragment,e),lt=n(e),M(K.$$.fragment,e),st=n(e),D=i(e,"P",{"data-svelte-h":!0}),d(D)!=="svelte-sq2btk"&&(D.innerHTML=At),at=n(e),O=i(e,"P",{"data-svelte-h":!0}),d(O)!=="svelte-a0z1wk"&&(O.innerHTML=St),nt=n(e),M(ee.$$.fragment,e),pt=n(e),M(te.$$.fragment,e),it=n(e),le=i(e,"P",{"data-svelte-h":!0}),d(le)!=="svelte-18p5bki"&&(le.innerHTML=qt),rt=n(e),se=i(e,"P",{"data-svelte-h":!0}),d(se)!=="svelte-1w33g61"&&(se.innerHTML=Lt),Mt=n(e),M(ae.$$.fragment,e),mt=n(e),ne=i(e,"P",{"data-svelte-h":!0}),d(ne)!=="svelte-1ed0ahl"&&(ne.textContent=Pt),ot=n(e),M(pe.$$.fragment,e),ct=n(e),ie=i(e,"P",{"data-svelte-h":!0}),d(ie)!=="svelte-196stsi"&&(ie.innerHTML=Kt),yt=n(e),M(re.$$.fragment,e),dt=n(e),Me=i(e,"P",{"data-svelte-h":!0}),d(Me)!=="svelte-1dxqkna"&&(Me.textContent=Dt),ft=n(e),me=i(e,"P",{"data-svelte-h":!0}),d(me)!=="svelte-z45nl5"&&(me.innerHTML=Ot),wt=n(e),M(oe.$$.fragment,e),ut=n(e),M(ce.$$.fragment,e),Jt=n(e),ye=i(e,"P",{"data-svelte-h":!0}),d(ye)!=="svelte-ddk3b2"&&(ye.innerHTML=el),bt=n(e),M(de.$$.fragment,e),Tt=n(e),T=i(e,"DIV",{class:!0,"data-svelte-h":!0}),d(T)!=="svelte-16i041b"&&(T.innerHTML=tl),ht=n(e),fe=i(e,"P",{"data-svelte-h":!0}),d(fe)!=="svelte-1ir3qqf"&&(fe.textContent=ll),Ut=n(e),M(we.$$.fragment,e),jt=n(e),ue=i(e,"P",{"data-svelte-h":!0}),d(ue)!=="svelte-1r7c47b"&&(ue.innerHTML=sl),gt=n(e),M(Je.$$.fragment,e),$t=n(e),M(be.$$.fragment,e),Ct=n(e),Te=i(e,"P",{"data-svelte-h":!0}),d(Te)!=="svelte-1xn05po"&&(Te.textContent=al),_t=n(e),M(he.$$.fragment,e),kt=n(e),ge=i(e,"P",{}),pl(ge).forEach(l),this.h()},h(){Bt(w,"name","hf:doc:metadata"),Bt(w,"content",bl),Bt(b,"class","flex justify-center"),Bt(T,"class","flex justify-center")},m(e,t){yl(document.head,w),s(e,h,t),s(e,u,t),s(e,je,t),m(U,e,t),s(e,Ce,t),m(j,e,t),s(e,_e,t),s(e,g,t),s(e,ke,t),s(e,$,t),s(e,ve,t),s(e,C,t),s(e,Be,t),s(e,_,t),s(e,We,t),m(k,e,t),s(e,Ie,t),s(e,v,t),s(e,Ze,t),m(B,e,t),s(e,Ge,t),m(W,e,t),s(e,xe,t),s(e,I,t),s(e,Re,t),m(Z,e,t),s(e,Xe,t),m(G,e,t),s(e,He,t),s(e,x,t),s(e,Ve,t),m(J,e,t),s(e,Ye,t),s(e,R,t),s(e,Ee,t),m(X,e,t),s(e,Qe,t),s(e,H,t),s(e,Ne,t),m(V,e,t),s(e,ze,t),s(e,b,t),s(e,Fe,t),m(Y,e,t),s(e,Ae,t),s(e,E,t),s(e,Se,t),s(e,Q,t),s(e,qe,t),m(N,e,t),s(e,Le,t),s(e,z,t),s(e,Pe,t),m(F,e,t),s(e,Ke,t),s(e,A,t),s(e,De,t),m(S,e,t),s(e,Oe,t),s(e,q,t),s(e,et,t),m(L,e,t),s(e,tt,t),m(P,e,t),s(e,lt,t),m(K,e,t),s(e,st,t),s(e,D,t),s(e,at,t),s(e,O,t),s(e,nt,t),m(ee,e,t),s(e,pt,t),m(te,e,t),s(e,it,t),s(e,le,t),s(e,rt,t),s(e,se,t),s(e,Mt,t),m(ae,e,t),s(e,mt,t),s(e,ne,t),s(e,ot,t),m(pe,e,t),s(e,ct,t),s(e,ie,t),s(e,yt,t),m(re,e,t),s(e,dt,t),s(e,Me,t),s(e,ft,t),s(e,me,t),s(e,wt,t),m(oe,e,t),s(e,ut,t),m(ce,e,t),s(e,Jt,t),s(e,ye,t),s(e,bt,t),m(de,e,t),s(e,Tt,t),s(e,T,t),s(e,ht,t),s(e,fe,t),s(e,Ut,t),m(we,e,t),s(e,jt,t),s(e,ue,t),s(e,gt,t),m(Je,e,t),s(e,$t,t),m(be,e,t),s(e,Ct,t),s(e,Te,t),s(e,_t,t),m(he,e,t),s(e,kt,t),s(e,ge,t),vt=!0},p(e,[t]){const nl={};t&2&&(nl.$$scope={dirty:t,ctx:e}),J.$set(nl)},i(e){vt||(o(U.$$.fragment,e),o(j.$$.fragment,e),o(k.$$.fragment,e),o(B.$$.fragment,e),o(W.$$.fragment,e),o(Z.$$.fragment,e),o(G.$$.fragment,e),o(J.$$.fragment,e),o(X.$$.fragment,e),o(V.$$.fragment,e),o(Y.$$.fragment,e),o(N.$$.fragment,e),o(F.$$.fragment,e),o(S.$$.fragment,e),o(L.$$.fragment,e),o(P.$$.fragment,e),o(K.$$.fragment,e),o(ee.$$.fragment,e),o(te.$$.fragment,e),o(ae.$$.fragment,e),o(pe.$$.fragment,e),o(re.$$.fragment,e),o(oe.$$.fragment,e),o(ce.$$.fragment,e),o(de.$$.fragment,e),o(we.$$.fragment,e),o(Je.$$.fragment,e),o(be.$$.fragment,e),o(he.$$.fragment,e),vt=!0)},o(e){c(U.$$.fragment,e),c(j.$$.fragment,e),c(k.$$.fragment,e),c(B.$$.fragment,e),c(W.$$.fragment,e),c(Z.$$.fragment,e),c(G.$$.fragment,e),c(J.$$.fragment,e),c(X.$$.fragment,e),c(V.$$.fragment,e),c(Y.$$.fragment,e),c(N.$$.fragment,e),c(F.$$.fragment,e),c(S.$$.fragment,e),c(L.$$.fragment,e),c(P.$$.fragment,e),c(K.$$.fragment,e),c(ee.$$.fragment,e),c(te.$$.fragment,e),c(ae.$$.fragment,e),c(pe.$$.fragment,e),c(re.$$.fragment,e),c(oe.$$.fragment,e),c(ce.$$.fragment,e),c(de.$$.fragment,e),c(we.$$.fragment,e),c(Je.$$.fragment,e),c(be.$$.fragment,e),c(he.$$.fragment,e),vt=!1},d(e){e&&(l(h),l(u),l(je),l(Ce),l(_e),l(g),l(ke),l($),l(ve),l(C),l(Be),l(_),l(We),l(Ie),l(v),l(Ze),l(Ge),l(xe),l(I),l(Re),l(Xe),l(He),l(x),l(Ve),l(Ye),l(R),l(Ee),l(Qe),l(H),l(Ne),l(ze),l(b),l(Fe),l(Ae),l(E),l(Se),l(Q),l(qe),l(Le),l(z),l(Pe),l(Ke),l(A),l(De),l(Oe),l(q),l(et),l(tt),l(lt),l(st),l(D),l(at),l(O),l(nt),l(pt),l(it),l(le),l(rt),l(se),l(Mt),l(mt),l(ne),l(ot),l(ct),l(ie),l(yt),l(dt),l(Me),l(ft),l(me),l(wt),l(ut),l(Jt),l(ye),l(bt),l(Tt),l(T),l(ht),l(fe),l(Ut),l(jt),l(ue),l(gt),l($t),l(Ct),l(Te),l(_t),l(kt),l(ge)),l(w),y(U,e),y(j,e),y(k,e),y(B,e),y(W,e),y(Z,e),y(G,e),y(J,e),y(X,e),y(V,e),y(Y,e),y(N,e),y(F,e),y(S,e),y(L,e),y(P,e),y(K,e),y(ee,e),y(te,e),y(ae,e),y(pe,e),y(re,e),y(oe,e),y(ce,e),y(de,e),y(we,e),y(Je,e),y(be,e),y(he,e)}}}const bl='{"title":"Image captioning","local":"image-captioning","sections":[{"title":"Load the Pokémon BLIP captions dataset","local":"load-the-pokémon-blip-captions-dataset","sections":[],"depth":2},{"title":"Preprocess the dataset","local":"preprocess-the-dataset","sections":[],"depth":2},{"title":"Load a base model","local":"load-a-base-model","sections":[],"depth":2},{"title":"Evaluate","local":"evaluate","sections":[],"depth":2},{"title":"Train!","local":"train","sections":[],"depth":2},{"title":"Inference","local":"inference","sections":[],"depth":2}],"depth":1}';function Tl($e){return rl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class _l extends ml{constructor(w){super(),ol(this,w,Tl,Jl,il,{})}}export{_l as component};
