import{s as ll,o as sl,n as al}from"../chunks/scheduler.56730f09.js";import{S as nl,i as pl,g as p,s as a,r as M,m as il,A as Ml,h as i,f as l,c as n,j as tl,u as m,x as d,n as ml,k as Ct,y as rl,a as s,v as r,d as o,t as c,w as y}from"../chunks/index.1f144517.js";import{T as ol}from"../chunks/Tip.41e845e5.js";import{C as f}from"../chunks/CodeBlock.738eeccb.js";import{D as cl}from"../chunks/DocNotebookDropdown.243c3df7.js";import{H as Te,E as yl}from"../chunks/EditOnGithub.854793f1.js";function dl(je){let J,U=`많은 이미지 캡션 데이터세트에는 이미지당 여러 개의 캡션이 포함되어 있습니다.
이러한 경우, 일반적으로 학습 중에 사용 가능한 캡션 중에서 무작위로 샘플을 추출합니다.`;return{c(){J=p("p"),J.textContent=U},l(w){J=i(w,"P",{"data-svelte-h":!0}),d(J)!=="svelte-82zair"&&(J.textContent=U)},m(w,Ue){s(w,J,Ue)},p:al,d(w){w&&l(J)}}}function fl(je){let J,U,w,Ue,h,ge,j,$e,g,_t=`이미지 캡셔닝(Image captioning)은 주어진 이미지에 대한 캡션을 예측하는 작업입니다.
이미지 캡셔닝은 시각 장애인이 다양한 상황을 탐색하는 데 도움을 줄 수 있도록 시각 장애인을 보조하는 등 실생활에서 흔히 활용됩니다.
따라서 이미지 캡셔닝은 이미지를 설명함으로써 사람들의 콘텐츠 접근성을 개선하는 데 도움이 됩니다.`,Ce,$,kt="이 가이드에서는 소개할 내용은 아래와 같습니다:",_e,C,It="<li>이미지 캡셔닝 모델을 파인튜닝합니다.</li> <li>파인튜닝된 모델을 추론에 사용합니다.</li>",ke,_,Bt="시작하기 전에 필요한 모든 라이브러리가 설치되어 있는지 확인하세요:",Ie,k,Be,I,Wt=`Hugging Face 계정에 로그인하면 모델을 업로드하고 커뮤니티에 공유할 수 있습니다.
토큰을 입력하여 로그인하세요.`,We,B,Ze,W,ve,Z,Zt=`{이미지-캡션} 쌍으로 구성된 데이터세트를 가져오려면 🤗 Dataset 라이브러리를 사용합니다.
PyTorch에서 자신만의 이미지 캡션 데이터세트를 만들려면 <a href="https://github.com/NielsRogge/Transformers-Tutorials/blob/master/GIT/Fine_tune_GIT_on_an_image_captioning_dataset.ipynb" rel="nofollow">이 노트북</a>을 참조하세요.`,Ge,v,xe,G,Re,x,vt="이 데이터세트는 <code>image</code>와 <code>text</code>라는 두 특성을 가지고 있습니다.",He,u,Xe,R,Gt="<code>train_test_split</code> 메소드를 사용하여 데이터세트의 학습 분할을 학습 및 테스트 세트로 나눕니다:",Ve,H,Ye,X,xt=`학습 세트의 샘플 몇 개를 시각화해 봅시다.
Let’s visualize a couple of samples from the training set.`,Ee,V,ze,b,Rt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/sample_training_images_image_cap.png" alt="Sample training images"/>',Qe,Y,Ne,E,Ht="데이터세트에는 이미지와 텍스트라는 두 가지 양식이 있기 때문에, 전처리 파이프라인에서 이미지와 캡션을 모두 전처리합니다.",Fe,z,Xt="전처리 작업을 위해, 파인튜닝하려는 모델에 연결된 프로세서 클래스를 가져옵니다.",Ae,Q,Se,N,Vt="프로세서는 내부적으로 크기 조정 및 픽셀 크기 조정을 포함한 이미지 전처리를 수행하고 캡션을 토큰화합니다.",qe,F,Le,A,Yt="데이터세트가 준비되었으니 이제 파인튜닝을 위해 모델을 설정할 수 있습니다.",Pe,S,Ke,q,Et='<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> 객체로 가져옵니다.',De,L,Oe,P,et,K,zt=`이미지 캡션 모델은 일반적으로 <a href="https://huggingface.co/spaces/evaluate-metric/rouge" rel="nofollow">Rouge 점수</a> 또는 <a href="https://huggingface.co/spaces/evaluate-metric/wer" rel="nofollow">단어 오류율(Word Error Rate)</a>로 평가합니다.
이 가이드에서는 단어 오류율(WER)을 사용합니다.`,tt,D,Qt=`이를 위해 🤗 Evaluate 라이브러리를 사용합니다.
WER의 잠재적 제한 사항 및 기타 문제점은 <a href="https://huggingface.co/spaces/evaluate-metric/wer" rel="nofollow">이 가이드</a>를 참조하세요.`,lt,O,st,ee,at,te,Nt="이제 모델 파인튜닝을 시작할 준비가 되었습니다. 이를 위해 🤗 <code>Trainer</code>를 사용합니다.",nt,le,Ft="먼저, <code>TrainingArguments</code>를 사용하여 학습 인수를 정의합니다.",pt,se,it,ae,At="학습 인수를 데이터세트, 모델과 함께 🤗 Trainer에 전달합니다.",Mt,ne,mt,pe,St="학습을 시작하려면 <code>Trainer</code> 객체에서 <code>train()</code>을 호출하기만 하면 됩니다.",rt,ie,ot,Me,qt="학습이 진행되면서 학습 손실이 원활하게 감소하는 것을 볼 수 있습니다.",ct,me,Lt="학습이 완료되면 모든 사람이 모델을 사용할 수 있도록 <code>push_to_hub()</code> 메소드를 사용하여 모델을 허브에 공유하세요:",yt,re,dt,oe,ft,ce,Pt="<code>test_ds</code>에서 샘플 이미지를 가져와 모델을 테스트합니다.",Jt,ye,wt,T,Kt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/test_image_image_cap.png" alt="Test image"/>',ut,de,bt,fe,Dt="<code>generate</code>를 호출하고 예측을 디코딩합니다.",Tt,Je,Ut,we,ht,ue,Ot="파인튜닝된 모델이 꽤 괜찮은 캡션을 생성한 것 같습니다!",jt,be,gt,he,$t;return h=new Te({props:{title:"이미지 캡셔닝",local:"image-captioning",headingTag:"h1"}}),j=new cl({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/ko/image_captioning.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/tensorflow/image_captioning.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/image_captioning.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/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 Te({props:{title:"포켓몬 BLIP 캡션 데이터세트 가져오기",local:"load-the-pokmon-blip-captions-dataset",headingTag:"h2"}}),v=new f({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`,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}}),u=new ol({props:{$$slots:{default:[dl]},$$scope:{ctx:je}}}),H=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 Te({props:{title:"데이터세트 전처리",local:"preprocess-the-dataset",headingTag:"h2"}}),Q=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 Te({props:{title:"기본 모델 가져오기",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 Te({props:{title:"평가",local:"evaluate",headingTag:"h2"}}),O=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}}),ee=new Te({props:{title:"학습!",local:"train!",headingTag:"h2"}}),se=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}}),ne=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}}),ie=new f({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),re=new f({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),oe=new Te({props:{title:"추론",local:"inference",headingTag:"h2"}}),ye=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}}),de=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}}),we=new f({props:{code:"YSUyMGRyYXdpbmclMjBvZiUyMGElMjBwaW5rJTIwYW5kJTIwYmx1ZSUyMHBva2Vtb24=",highlighted:"a drawing of a pink and blue pokemon",wrap:!1}}),be=new yl({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/tasks/image_captioning.md"}}),{c(){J=p("meta"),U=a(),w=p("p"),Ue=a(),M(h.$$.fragment),ge=a(),M(j.$$.fragment),$e=a(),g=p("p"),g.textContent=_t,Ce=a(),$=p("p"),$.textContent=kt,_e=a(),C=p("ul"),C.innerHTML=It,ke=a(),_=p("p"),_.textContent=Bt,Ie=a(),M(k.$$.fragment),Be=a(),I=p("p"),I.textContent=Wt,We=a(),M(B.$$.fragment),Ze=a(),M(W.$$.fragment),ve=a(),Z=p("p"),Z.innerHTML=Zt,Ge=a(),M(v.$$.fragment),xe=a(),M(G.$$.fragment),Re=a(),x=p("p"),x.innerHTML=vt,He=a(),M(u.$$.fragment),Xe=a(),R=p("p"),R.innerHTML=Gt,Ve=a(),M(H.$$.fragment),Ye=a(),X=p("p"),X.textContent=xt,Ee=a(),M(V.$$.fragment),ze=a(),b=p("div"),b.innerHTML=Rt,Qe=a(),M(Y.$$.fragment),Ne=a(),E=p("p"),E.textContent=Ht,Fe=a(),z=p("p"),z.textContent=Xt,Ae=a(),M(Q.$$.fragment),Se=a(),N=p("p"),N.textContent=Vt,qe=a(),M(F.$$.fragment),Le=a(),A=p("p"),A.textContent=Yt,Pe=a(),M(S.$$.fragment),Ke=a(),q=p("p"),q.innerHTML=Et,De=a(),M(L.$$.fragment),Oe=a(),M(P.$$.fragment),et=a(),K=p("p"),K.innerHTML=zt,tt=a(),D=p("p"),D.innerHTML=Qt,lt=a(),M(O.$$.fragment),st=a(),M(ee.$$.fragment),at=a(),te=p("p"),te.innerHTML=Nt,nt=a(),le=p("p"),le.innerHTML=Ft,pt=a(),M(se.$$.fragment),it=a(),ae=p("p"),ae.textContent=At,Mt=a(),M(ne.$$.fragment),mt=a(),pe=p("p"),pe.innerHTML=St,rt=a(),M(ie.$$.fragment),ot=a(),Me=p("p"),Me.textContent=qt,ct=a(),me=p("p"),me.innerHTML=Lt,yt=a(),M(re.$$.fragment),dt=a(),M(oe.$$.fragment),ft=a(),ce=p("p"),ce.innerHTML=Pt,Jt=a(),M(ye.$$.fragment),wt=a(),T=p("div"),T.innerHTML=Kt,ut=il(`
    
모델에 사용할 이미지를 준비합니다.

	`),M(de.$$.fragment),bt=a(),fe=p("p"),fe.innerHTML=Dt,Tt=a(),M(Je.$$.fragment),Ut=a(),M(we.$$.fragment),ht=a(),ue=p("p"),ue.textContent=Ot,jt=a(),M(be.$$.fragment),gt=a(),he=p("p"),this.h()},l(e){const t=Ml("svelte-u9bgzb",document.head);J=i(t,"META",{name:!0,content:!0}),t.forEach(l),U=n(e),w=i(e,"P",{}),tl(w).forEach(l),Ue=n(e),m(h.$$.fragment,e),ge=n(e),m(j.$$.fragment,e),$e=n(e),g=i(e,"P",{"data-svelte-h":!0}),d(g)!=="svelte-1sz2sm4"&&(g.textContent=_t),Ce=n(e),$=i(e,"P",{"data-svelte-h":!0}),d($)!=="svelte-tq3033"&&($.textContent=kt),_e=n(e),C=i(e,"UL",{"data-svelte-h":!0}),d(C)!=="svelte-htt0z1"&&(C.innerHTML=It),ke=n(e),_=i(e,"P",{"data-svelte-h":!0}),d(_)!=="svelte-18iigii"&&(_.textContent=Bt),Ie=n(e),m(k.$$.fragment,e),Be=n(e),I=i(e,"P",{"data-svelte-h":!0}),d(I)!=="svelte-9xxxb4"&&(I.textContent=Wt),We=n(e),m(B.$$.fragment,e),Ze=n(e),m(W.$$.fragment,e),ve=n(e),Z=i(e,"P",{"data-svelte-h":!0}),d(Z)!=="svelte-fdtyxx"&&(Z.innerHTML=Zt),Ge=n(e),m(v.$$.fragment,e),xe=n(e),m(G.$$.fragment,e),Re=n(e),x=i(e,"P",{"data-svelte-h":!0}),d(x)!=="svelte-1ff7g97"&&(x.innerHTML=vt),He=n(e),m(u.$$.fragment,e),Xe=n(e),R=i(e,"P",{"data-svelte-h":!0}),d(R)!=="svelte-1pxdo64"&&(R.innerHTML=Gt),Ve=n(e),m(H.$$.fragment,e),Ye=n(e),X=i(e,"P",{"data-svelte-h":!0}),d(X)!=="svelte-1xgsiym"&&(X.textContent=xt),Ee=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=Rt),Qe=n(e),m(Y.$$.fragment,e),Ne=n(e),E=i(e,"P",{"data-svelte-h":!0}),d(E)!=="svelte-15c40fh"&&(E.textContent=Ht),Fe=n(e),z=i(e,"P",{"data-svelte-h":!0}),d(z)!=="svelte-aj1022"&&(z.textContent=Xt),Ae=n(e),m(Q.$$.fragment,e),Se=n(e),N=i(e,"P",{"data-svelte-h":!0}),d(N)!=="svelte-lek9ik"&&(N.textContent=Vt),qe=n(e),m(F.$$.fragment,e),Le=n(e),A=i(e,"P",{"data-svelte-h":!0}),d(A)!=="svelte-x9apz1"&&(A.textContent=Yt),Pe=n(e),m(S.$$.fragment,e),Ke=n(e),q=i(e,"P",{"data-svelte-h":!0}),d(q)!=="svelte-1ifqfke"&&(q.innerHTML=Et),De=n(e),m(L.$$.fragment,e),Oe=n(e),m(P.$$.fragment,e),et=n(e),K=i(e,"P",{"data-svelte-h":!0}),d(K)!=="svelte-1i0maa4"&&(K.innerHTML=zt),tt=n(e),D=i(e,"P",{"data-svelte-h":!0}),d(D)!=="svelte-gcfhpv"&&(D.innerHTML=Qt),lt=n(e),m(O.$$.fragment,e),st=n(e),m(ee.$$.fragment,e),at=n(e),te=i(e,"P",{"data-svelte-h":!0}),d(te)!=="svelte-1p0jzke"&&(te.innerHTML=Nt),nt=n(e),le=i(e,"P",{"data-svelte-h":!0}),d(le)!=="svelte-1rmrex2"&&(le.innerHTML=Ft),pt=n(e),m(se.$$.fragment,e),it=n(e),ae=i(e,"P",{"data-svelte-h":!0}),d(ae)!=="svelte-14i42sb"&&(ae.textContent=At),Mt=n(e),m(ne.$$.fragment,e),mt=n(e),pe=i(e,"P",{"data-svelte-h":!0}),d(pe)!=="svelte-14yorud"&&(pe.innerHTML=St),rt=n(e),m(ie.$$.fragment,e),ot=n(e),Me=i(e,"P",{"data-svelte-h":!0}),d(Me)!=="svelte-cnq009"&&(Me.textContent=qt),ct=n(e),me=i(e,"P",{"data-svelte-h":!0}),d(me)!=="svelte-106657s"&&(me.innerHTML=Lt),yt=n(e),m(re.$$.fragment,e),dt=n(e),m(oe.$$.fragment,e),ft=n(e),ce=i(e,"P",{"data-svelte-h":!0}),d(ce)!=="svelte-noj8gs"&&(ce.innerHTML=Pt),Jt=n(e),m(ye.$$.fragment,e),wt=n(e),T=i(e,"DIV",{class:!0,"data-svelte-h":!0}),d(T)!=="svelte-yvzmn4"&&(T.innerHTML=Kt),ut=ml(e,`
    
모델에 사용할 이미지를 준비합니다.

	`),m(de.$$.fragment,e),bt=n(e),fe=i(e,"P",{"data-svelte-h":!0}),d(fe)!=="svelte-1o736s1"&&(fe.innerHTML=Dt),Tt=n(e),m(Je.$$.fragment,e),Ut=n(e),m(we.$$.fragment,e),ht=n(e),ue=i(e,"P",{"data-svelte-h":!0}),d(ue)!=="svelte-1ye6o6q"&&(ue.textContent=Ot),jt=n(e),m(be.$$.fragment,e),gt=n(e),he=i(e,"P",{}),tl(he).forEach(l),this.h()},h(){Ct(J,"name","hf:doc:metadata"),Ct(J,"content",Jl),Ct(b,"class","flex justify-center"),Ct(T,"class","flex justify-center")},m(e,t){rl(document.head,J),s(e,U,t),s(e,w,t),s(e,Ue,t),r(h,e,t),s(e,ge,t),r(j,e,t),s(e,$e,t),s(e,g,t),s(e,Ce,t),s(e,$,t),s(e,_e,t),s(e,C,t),s(e,ke,t),s(e,_,t),s(e,Ie,t),r(k,e,t),s(e,Be,t),s(e,I,t),s(e,We,t),r(B,e,t),s(e,Ze,t),r(W,e,t),s(e,ve,t),s(e,Z,t),s(e,Ge,t),r(v,e,t),s(e,xe,t),r(G,e,t),s(e,Re,t),s(e,x,t),s(e,He,t),r(u,e,t),s(e,Xe,t),s(e,R,t),s(e,Ve,t),r(H,e,t),s(e,Ye,t),s(e,X,t),s(e,Ee,t),r(V,e,t),s(e,ze,t),s(e,b,t),s(e,Qe,t),r(Y,e,t),s(e,Ne,t),s(e,E,t),s(e,Fe,t),s(e,z,t),s(e,Ae,t),r(Q,e,t),s(e,Se,t),s(e,N,t),s(e,qe,t),r(F,e,t),s(e,Le,t),s(e,A,t),s(e,Pe,t),r(S,e,t),s(e,Ke,t),s(e,q,t),s(e,De,t),r(L,e,t),s(e,Oe,t),r(P,e,t),s(e,et,t),s(e,K,t),s(e,tt,t),s(e,D,t),s(e,lt,t),r(O,e,t),s(e,st,t),r(ee,e,t),s(e,at,t),s(e,te,t),s(e,nt,t),s(e,le,t),s(e,pt,t),r(se,e,t),s(e,it,t),s(e,ae,t),s(e,Mt,t),r(ne,e,t),s(e,mt,t),s(e,pe,t),s(e,rt,t),r(ie,e,t),s(e,ot,t),s(e,Me,t),s(e,ct,t),s(e,me,t),s(e,yt,t),r(re,e,t),s(e,dt,t),r(oe,e,t),s(e,ft,t),s(e,ce,t),s(e,Jt,t),r(ye,e,t),s(e,wt,t),s(e,T,t),s(e,ut,t),r(de,e,t),s(e,bt,t),s(e,fe,t),s(e,Tt,t),r(Je,e,t),s(e,Ut,t),r(we,e,t),s(e,ht,t),s(e,ue,t),s(e,jt,t),r(be,e,t),s(e,gt,t),s(e,he,t),$t=!0},p(e,[t]){const el={};t&2&&(el.$$scope={dirty:t,ctx:e}),u.$set(el)},i(e){$t||(o(h.$$.fragment,e),o(j.$$.fragment,e),o(k.$$.fragment,e),o(B.$$.fragment,e),o(W.$$.fragment,e),o(v.$$.fragment,e),o(G.$$.fragment,e),o(u.$$.fragment,e),o(H.$$.fragment,e),o(V.$$.fragment,e),o(Y.$$.fragment,e),o(Q.$$.fragment,e),o(F.$$.fragment,e),o(S.$$.fragment,e),o(L.$$.fragment,e),o(P.$$.fragment,e),o(O.$$.fragment,e),o(ee.$$.fragment,e),o(se.$$.fragment,e),o(ne.$$.fragment,e),o(ie.$$.fragment,e),o(re.$$.fragment,e),o(oe.$$.fragment,e),o(ye.$$.fragment,e),o(de.$$.fragment,e),o(Je.$$.fragment,e),o(we.$$.fragment,e),o(be.$$.fragment,e),$t=!0)},o(e){c(h.$$.fragment,e),c(j.$$.fragment,e),c(k.$$.fragment,e),c(B.$$.fragment,e),c(W.$$.fragment,e),c(v.$$.fragment,e),c(G.$$.fragment,e),c(u.$$.fragment,e),c(H.$$.fragment,e),c(V.$$.fragment,e),c(Y.$$.fragment,e),c(Q.$$.fragment,e),c(F.$$.fragment,e),c(S.$$.fragment,e),c(L.$$.fragment,e),c(P.$$.fragment,e),c(O.$$.fragment,e),c(ee.$$.fragment,e),c(se.$$.fragment,e),c(ne.$$.fragment,e),c(ie.$$.fragment,e),c(re.$$.fragment,e),c(oe.$$.fragment,e),c(ye.$$.fragment,e),c(de.$$.fragment,e),c(Je.$$.fragment,e),c(we.$$.fragment,e),c(be.$$.fragment,e),$t=!1},d(e){e&&(l(U),l(w),l(Ue),l(ge),l($e),l(g),l(Ce),l($),l(_e),l(C),l(ke),l(_),l(Ie),l(Be),l(I),l(We),l(Ze),l(ve),l(Z),l(Ge),l(xe),l(Re),l(x),l(He),l(Xe),l(R),l(Ve),l(Ye),l(X),l(Ee),l(ze),l(b),l(Qe),l(Ne),l(E),l(Fe),l(z),l(Ae),l(Se),l(N),l(qe),l(Le),l(A),l(Pe),l(Ke),l(q),l(De),l(Oe),l(et),l(K),l(tt),l(D),l(lt),l(st),l(at),l(te),l(nt),l(le),l(pt),l(it),l(ae),l(Mt),l(mt),l(pe),l(rt),l(ot),l(Me),l(ct),l(me),l(yt),l(dt),l(ft),l(ce),l(Jt),l(wt),l(T),l(ut),l(bt),l(fe),l(Tt),l(Ut),l(ht),l(ue),l(jt),l(gt),l(he)),l(J),y(h,e),y(j,e),y(k,e),y(B,e),y(W,e),y(v,e),y(G,e),y(u,e),y(H,e),y(V,e),y(Y,e),y(Q,e),y(F,e),y(S,e),y(L,e),y(P,e),y(O,e),y(ee,e),y(se,e),y(ne,e),y(ie,e),y(re,e),y(oe,e),y(ye,e),y(de,e),y(Je,e),y(we,e),y(be,e)}}}const Jl='{"title":"이미지 캡셔닝","local":"image-captioning","sections":[{"title":"포켓몬 BLIP 캡션 데이터세트 가져오기","local":"load-the-pokmon-blip-captions-dataset","sections":[],"depth":2},{"title":"데이터세트 전처리","local":"preprocess-the-dataset","sections":[],"depth":2},{"title":"기본 모델 가져오기","local":"load-a-base-model","sections":[],"depth":2},{"title":"평가","local":"evaluate","sections":[],"depth":2},{"title":"학습!","local":"train!","sections":[],"depth":2},{"title":"추론","local":"inference","sections":[],"depth":2}],"depth":1}';function wl(je){return sl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gl extends nl{constructor(J){super(),pl(this,J,wl,fl,ll,{})}}export{gl as component};
