import{s as re,o as pe,n as te}from"../chunks/scheduler.bdbef820.js";import{S as ie,i as me,g as h,s as r,r as u,A as oe,h as M,f as e,c as p,j as It,u as $,x as j,k as Ht,y as Gt,a,v as g,d as y,t as w,w as b}from"../chunks/index.33f81d56.js";import{T as ee}from"../chunks/Tip.34194030.js";import{Y as Ot}from"../chunks/Youtube.0e329b00.js";import{C as G}from"../chunks/CodeBlock.362b34a4.js";import{D as fe}from"../chunks/DocNotebookDropdown.d5db5928.js";import{F as ne,M as se}from"../chunks/Markdown.03194dea.js";import{H as Zt,E as de}from"../chunks/EditOnGithub.a9246e21.js";function ce(dt){let i,T=`사전 훈련된 가중치 중 일부가 사용되지 않고 일부 가중치가 무작위로 표시된다는 경고가 표시됩니다.
걱정마세요. 이것은 올바른 동작입니다! 사전 학습된 BERT 모델의 헤드는 폐기되고 무작위로 초기화된 분류 헤드로 대체됩니다. 이제 사전 학습된 모델의 지식으로 시퀀스 분류 작업을 위한 새로운 모델 헤드를 미세 튜닝 합니다.`;return{c(){i=h("p"),i.textContent=T},l(m){i=M(m,"P",{"data-svelte-h":!0}),j(i)!=="svelte-133r2kc"&&(i.textContent=T)},m(m,J){a(m,i,J)},p:te,d(m){m&&e(i)}}}function he(dt){let i,T,m,J,k,nt='🤗 Transformers는 🤗 Transformers 모델 훈련에 최적화된 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a> 클래스를 제공하여 훈련 루프를 직접 작성하지 않고도 쉽게 훈련을 시작할 수 있습니다. <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a> API는 로깅(logging), 경사 누적(gradient accumulation), 혼합 정밀도(mixed precision) 등 다양한 훈련 옵션과 기능을 지원합니다.',A,rt,L='먼저 모델을 가져오고 예상되는 레이블 수를 지정합니다. Yelp 리뷰 <a href="https://huggingface.co/datasets/yelp_review_full#data-fields" rel="nofollow">데이터셋 카드</a>에서 5개의 레이블이 있음을 알 수 있습니다:',pt,R,Q,ct,W,U,ht,q,Mt='다음으로 정할 수 있는 모든 하이퍼파라미터와 다양한 훈련 옵션을 활성화하기 위한 플래그를 포함하는 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> 클래스를 생성합니다.',X,H,at='이 튜토리얼에서는 기본 훈련 <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments" rel="nofollow">하이퍼파라미터</a>로 시작하지만, 자유롭게 실험하여 여러분들에게 맞는 최적의 설정을 찾을 수 있습니다.',ut,S,$t="훈련에서 체크포인트(checkpoints)를 저장할 위치를 지정합니다:",P,gt,V,I,it,K,mt=`<a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>는 훈련 중에 모델 성능을 자동으로 평가하지 않습니다. 평가 지표를 계산하고 보고할 함수를 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>에 전달해야 합니다.
<a href="https://huggingface.co/docs/evaluate/index" rel="nofollow">🤗 Evaluate</a> 라이브러리는 <a href="https://huggingface.co/spaces/evaluate-metric/accuracy" rel="nofollow"><code>evaluate.load</code></a> 함수로 로드할 수 있는 간단한 <code>accuracy</code>함수를 제공합니다 (자세한 내용은 <a href="https://huggingface.co/docs/evaluate/a_quick_tour" rel="nofollow">둘러보기</a>를 참조하세요):`,x,D,ot,O,ft="<code>metric</code>에서 <code>compute</code>를 호출하여 예측의 정확도를 계산합니다. 예측을 <code>compute</code>에 전달하기 전에 예측을 로짓으로 변환해야 합니다(모든 🤗 Transformers 모델은 로짓으로 반환한다는 점을 기억하세요):",F,tt,lt,v,kt="미세 튜닝 중에 평가 지표를 모니터링하려면 훈련 인수에 <code>eval_strategy</code> 파라미터를 지정하여 각 에폭이 끝날 때 평가 지표를 확인할 수 있습니다:",yt,Z,Ut,z,N,et,Y='모델, 훈련 인수, 훈련 및 테스트 데이터셋, 평가 함수가 포함된 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a> 객체를 만듭니다:',Tt,C,st,_,bt='그리고 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer.train">train()</a>을 호출하여 모델을 미세 튜닝합니다:',wt,B,E;return i=new Ot({props:{id:"nvBXf7s7vTI"}}),m=new Zt({props:{title:"파이토치 Trainer로 훈련하기",local:"train-with-pytorch-trainer",headingTag:"h2"}}),R=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZS1iZXJ0JTJGYmVydC1iYXNlLWNhc2VkJTIyJTJDJTIwbnVtX2xhYmVscyUzRDUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>, num_labels=<span class="hljs-number">5</span>)`,wrap:!1}}),ct=new ee({props:{$$slots:{default:[ce]},$$scope:{ctx:dt}}}),U=new Zt({props:{title:"하이퍼파라미터 훈련",local:"training-hyperparameters",headingTag:"h3"}}),gt=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKG91dHB1dF9kaXIlM0QlMjJ0ZXN0X3RyYWluZXIlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(output_dir=<span class="hljs-string">&quot;test_trainer&quot;</span>)`,wrap:!1}}),I=new Zt({props:{title:"평가 하기",local:"evaluate",headingTag:"h3"}}),D=new G({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmFjY3VyYWN5JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)`,wrap:!1}}),tt=new G({props:{code:"ZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWQlMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyMCUzRCUyMG5wLmFyZ21heChsb2dpdHMlMkMlMjBheGlzJTNELTEpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RwcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0RsYWJlbHMp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    logits, labels = eval_pred
<span class="hljs-meta">... </span>    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> metric.compute(predictions=predictions, references=labels)`,wrap:!1}}),Z=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyhvdXRwdXRfZGlyJTNEJTIydGVzdF90cmFpbmVyJTIyJTJDJTIwZXZhbF9zdHJhdGVneSUzRCUyMmVwb2NoJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(output_dir=<span class="hljs-string">&quot;test_trainer&quot;</span>, eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>)`,wrap:!1}}),z=new Zt({props:{title:"훈련 하기",local:"trainer",headingTag:"h3"}}),C=new G({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHNtYWxsX3RyYWluX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0RzbWFsbF9ldmFsX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=small_train_dataset,
<span class="hljs-meta">... </span>    eval_dataset=small_eval_dataset,
<span class="hljs-meta">... </span>    compute_metrics=compute_metrics,
<span class="hljs-meta">... </span>)`,wrap:!1}}),B=new G({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()',wrap:!1}}),{c(){u(i.$$.fragment),T=r(),u(m.$$.fragment),J=r(),k=h("p"),k.innerHTML=nt,A=r(),rt=h("p"),rt.innerHTML=L,pt=r(),u(R.$$.fragment),Q=r(),u(ct.$$.fragment),W=r(),u(U.$$.fragment),ht=r(),q=h("p"),q.innerHTML=Mt,X=r(),H=h("p"),H.innerHTML=at,ut=r(),S=h("p"),S.textContent=$t,P=r(),u(gt.$$.fragment),V=r(),u(I.$$.fragment),it=r(),K=h("p"),K.innerHTML=mt,x=r(),u(D.$$.fragment),ot=r(),O=h("p"),O.innerHTML=ft,F=r(),u(tt.$$.fragment),lt=r(),v=h("p"),v.innerHTML=kt,yt=r(),u(Z.$$.fragment),Ut=r(),u(z.$$.fragment),N=r(),et=h("p"),et.innerHTML=Y,Tt=r(),u(C.$$.fragment),st=r(),_=h("p"),_.innerHTML=bt,wt=r(),u(B.$$.fragment)},l(l){$(i.$$.fragment,l),T=p(l),$(m.$$.fragment,l),J=p(l),k=M(l,"P",{"data-svelte-h":!0}),j(k)!=="svelte-1884tr5"&&(k.innerHTML=nt),A=p(l),rt=M(l,"P",{"data-svelte-h":!0}),j(rt)!=="svelte-vv5j33"&&(rt.innerHTML=L),pt=p(l),$(R.$$.fragment,l),Q=p(l),$(ct.$$.fragment,l),W=p(l),$(U.$$.fragment,l),ht=p(l),q=M(l,"P",{"data-svelte-h":!0}),j(q)!=="svelte-1x8k9vk"&&(q.innerHTML=Mt),X=p(l),H=M(l,"P",{"data-svelte-h":!0}),j(H)!=="svelte-17gf6c"&&(H.innerHTML=at),ut=p(l),S=M(l,"P",{"data-svelte-h":!0}),j(S)!=="svelte-3gh4w5"&&(S.textContent=$t),P=p(l),$(gt.$$.fragment,l),V=p(l),$(I.$$.fragment,l),it=p(l),K=M(l,"P",{"data-svelte-h":!0}),j(K)!=="svelte-14hzmkv"&&(K.innerHTML=mt),x=p(l),$(D.$$.fragment,l),ot=p(l),O=M(l,"P",{"data-svelte-h":!0}),j(O)!=="svelte-fpot8d"&&(O.innerHTML=ft),F=p(l),$(tt.$$.fragment,l),lt=p(l),v=M(l,"P",{"data-svelte-h":!0}),j(v)!=="svelte-6bm7jk"&&(v.innerHTML=kt),yt=p(l),$(Z.$$.fragment,l),Ut=p(l),$(z.$$.fragment,l),N=p(l),et=M(l,"P",{"data-svelte-h":!0}),j(et)!=="svelte-1yup1bi"&&(et.innerHTML=Y),Tt=p(l),$(C.$$.fragment,l),st=p(l),_=M(l,"P",{"data-svelte-h":!0}),j(_)!=="svelte-yiipct"&&(_.innerHTML=bt),wt=p(l),$(B.$$.fragment,l)},m(l,d){g(i,l,d),a(l,T,d),g(m,l,d),a(l,J,d),a(l,k,d),a(l,A,d),a(l,rt,d),a(l,pt,d),g(R,l,d),a(l,Q,d),g(ct,l,d),a(l,W,d),g(U,l,d),a(l,ht,d),a(l,q,d),a(l,X,d),a(l,H,d),a(l,ut,d),a(l,S,d),a(l,P,d),g(gt,l,d),a(l,V,d),g(I,l,d),a(l,it,d),a(l,K,d),a(l,x,d),g(D,l,d),a(l,ot,d),a(l,O,d),a(l,F,d),g(tt,l,d),a(l,lt,d),a(l,v,d),a(l,yt,d),g(Z,l,d),a(l,Ut,d),g(z,l,d),a(l,N,d),a(l,et,d),a(l,Tt,d),g(C,l,d),a(l,st,d),a(l,_,d),a(l,wt,d),g(B,l,d),E=!0},p(l,d){const jt={};d&2&&(jt.$$scope={dirty:d,ctx:l}),ct.$set(jt)},i(l){E||(y(i.$$.fragment,l),y(m.$$.fragment,l),y(R.$$.fragment,l),y(ct.$$.fragment,l),y(U.$$.fragment,l),y(gt.$$.fragment,l),y(I.$$.fragment,l),y(D.$$.fragment,l),y(tt.$$.fragment,l),y(Z.$$.fragment,l),y(z.$$.fragment,l),y(C.$$.fragment,l),y(B.$$.fragment,l),E=!0)},o(l){w(i.$$.fragment,l),w(m.$$.fragment,l),w(R.$$.fragment,l),w(ct.$$.fragment,l),w(U.$$.fragment,l),w(gt.$$.fragment,l),w(I.$$.fragment,l),w(D.$$.fragment,l),w(tt.$$.fragment,l),w(Z.$$.fragment,l),w(z.$$.fragment,l),w(C.$$.fragment,l),w(B.$$.fragment,l),E=!1},d(l){l&&(e(T),e(J),e(k),e(A),e(rt),e(pt),e(Q),e(W),e(ht),e(q),e(X),e(H),e(ut),e(S),e(P),e(V),e(it),e(K),e(x),e(ot),e(O),e(F),e(lt),e(v),e(yt),e(Ut),e(N),e(et),e(Tt),e(st),e(_),e(wt)),b(i,l),b(m,l),b(R,l),b(ct,l),b(U,l),b(gt,l),b(I,l),b(D,l),b(tt,l),b(Z,l),b(z,l),b(C,l),b(B,l)}}}function Me(dt){let i,T;return i=new se({props:{$$slots:{default:[he]},$$scope:{ctx:dt}}}),{c(){u(i.$$.fragment)},l(m){$(i.$$.fragment,m)},m(m,J){g(i,m,J),T=!0},p(m,J){const k={};J&2&&(k.$$scope={dirty:J,ctx:m}),i.$set(k)},i(m){T||(y(i.$$.fragment,m),T=!0)},o(m){w(i.$$.fragment,m),T=!1},d(m){b(i,m)}}}function ue(dt){let i,T=`모델을 <code>compile()</code>할 때 손실 인수를 모델에 전달할 필요가 없습니다!
이 인수를 비워두면 허깅 페이스 모델은 작업과 모델 아키텍처에 적합한 손실을 자동으로 선택합니다.
원한다면 언제든지 직접 손실을 지정하여 이를 재정의할 수 있습니다!`;return{c(){i=h("p"),i.innerHTML=T},l(m){i=M(m,"P",{"data-svelte-h":!0}),j(i)!=="svelte-z0fgk0"&&(i.innerHTML=T)},m(m,J){a(m,i,J)},p:te,d(m){m&&e(i)}}}function $e(dt){let i,T,m,J,k,nt,A,rt="Keras API를 사용하여 텐서플로우에서 🤗 Transformers 모델을 훈련할 수도 있습니다!",L,pt,R,Q,ct=`Keras API로 🤗 Transformers 모델을 학습시키려면 데이터셋을 Keras가 이해할 수 있는 형식으로 변환해야 합니다.
데이터 세트가 작은 경우, 전체를 NumPy 배열로 변환하여 Keras로 전달하면 됩니다.
더 복잡한 작업을 수행하기 전에 먼저 이 작업을 시도해 보겠습니다.`,W,U,ht=`먼저 데이터 세트를 로드합니다. <a href="https://huggingface.co/datasets/glue" rel="nofollow">GLUE 벤치마크</a>의 CoLA 데이터 세트를 사용하겠습니다.
간단한 바이너리 텍스트 분류 작업이므로 지금은 훈련 데이터 분할만 사용합니다.`,q,Mt,X,H,at="다음으로 토크나이저를 로드하고 데이터를 NumPy 배열로 토큰화합니다. 레이블은 이미 0과 1로 된 리스트이기 때문에 토큰화하지 않고 바로 NumPy 배열로 변환할 수 있습니다!",ut,S,$t,P,gt='마지막으로 모델을 로드, <a href="https://keras.io/api/models/model_training_apis/#compile-method" rel="nofollow"><code>compile</code></a>, <a href="https://keras.io/api/models/model_training_apis/#fit-method" rel="nofollow"><code>fit</code></a>합니다:',V,I,it,K,mt,x,D=`이 접근 방식은 소규모 데이터 집합에서는 잘 작동하지만, 대규모 데이터 집합에서는 문제가 될 수 있습니다. 왜 그럴까요?
토큰화된 배열과 레이블을 메모리에 완전히 로드하고 NumPy는 “들쭉날쭉한” 배열을 처리하지 않기 때문에,
모든 토큰화된 샘플을 전체 데이터셋에서 가장 긴 샘플의 길이만큼 패딩해야 합니다. 이렇게 하면 배열이 훨씬 더 커지고 이 패딩 토큰으로 인해 학습 속도도 느려집니다!`,ot,O,ft,F,tt=`학습 속도가 느려지는 것을 피하려면 데이터를 <code>tf.data.Dataset</code>으로 로드할 수 있습니다. 원한다면 직접
<code>tf.data</code> 파이프라인을 직접 작성할 수도 있지만, 이 작업을 간편하게 수행하는 수 있는 두 가지 방법이 있습니다:`,lt,v,kt=`<li><a href="/docs/transformers/main/ko/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset">prepare_tf_dataset()</a>: 대부분의 경우 이 방법을 권장합니다. 모델의 메서드이기 때문에 모델을 검사하여 모델 입력으로 사용할 수 있는 열을 자동으로 파악하고
나머지는 버려서 더 단순하고 성능이 좋은 데이터 집합을 만들 수 있습니다.</li> <li><code>to_tf_dataset</code>: 이 방법은 좀 더 낮은 수준이며, 포함할 ‘열’과 ‘레이블’을 정확히 지정하여
데이터셋을 생성하는 방법을 정확히 제어하고 싶을 때 유용하며, 포함할 ‘columns’과 ‘label_cols’을 정확히 지정할 수 있습니다.</li>`,yt,Z,Ut='<a href="/docs/transformers/main/ko/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset">prepare_tf_dataset()</a>을 사용하려면 먼저 다음 코드 샘플과 같이 토크나이저 출력을 데이터 세트에 열로 추가해야 합니다:',z,N,et,Y,Tt=`허깅 페이스 데이터셋은 기본적으로 디스크에 저장되므로 메모리 사용량을 늘리지 않는다는 점을 기억하세요!
열이 추가되면 데이터셋에서 배치를 스트리밍하고 각 배치에 패딩을 추가할 수 있으므로 전체 데이터셋에 패딩을 추가하는 것보다 패딩 토큰의 수를 크게 줄일 수 있습니다.`,C,st,_,bt,wt=`위의 코드 샘플에서는 배치가 로드될 때 올바르게 패딩할 수 있도록 <code>prepare_tf_dataset</code>에 토크나이저를 전달해야 합니다.
데이터셋의 모든 샘플 길이가 같고 패딩이 필요하지 않은 경우 이 인수를 건너뛸 수 있습니다.
샘플을 채우는 것보다 더 복잡한 작업(예: 마스킹된 언어의 토큰 손상 모델링)을 수행하기 위해 토큰을 손상시켜야 하는 경우,
<code>collate_fn</code> 인수를 사용하여 샘플 목록을 배치로 변환하고 원하는 전처리를 적용할 함수를 전달할 수 있습니다.
<a href="https://github.com/huggingface/transformers/tree/main/examples" rel="nofollow">예시</a> 또는
<a href="https://huggingface.co/docs/transformers/notebooks" rel="nofollow">노트북</a>을 참조하여 이 접근 방식이 실제로 작동하는 모습을 확인하세요.`,B,E,l="<code>tf.data.Dataset</code>을 생성한 후에는 이전과 마찬가지로 모델을 컴파일하고 훈련(fit)할 수 있습니다:",d,jt,Jt;return m=new Ot({props:{id:"rnTGBy2ax1c"}}),k=new Zt({props:{title:"Keras로 텐서플로우 모델 훈련하기",local:"train-a-tensorflow-model-with-keras",headingTag:"h2"}}),pt=new Zt({props:{title:"Keras용 데이터 로드",local:"loading-data-for-keras",headingTag:"h3"}}),Mt=new G({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwJTIyY29sYSUyMiklMEFkYXRhc2V0JTIwJTNEJTIwZGF0YXNldCU1QiUyMnRyYWluJTIyJTVEJTIwJTIwJTIzJTIwSnVzdCUyMHRha2UlMjB0aGUlMjB0cmFpbmluZyUyMHNwbGl0JTIwZm9yJTIwbm93",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

dataset = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;cola&quot;</span>)
dataset = dataset[<span class="hljs-string">&quot;train&quot;</span>]  <span class="hljs-comment"># Just take the training split for now</span>`,wrap:!1}}),S=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUtYmVydCUyRmJlcnQtYmFzZS1jYXNlZCUyMiklMEF0b2tlbml6ZWRfZGF0YSUyMCUzRCUyMHRva2VuaXplcihkYXRhc2V0JTVCJTIyc2VudGVuY2UlMjIlNUQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMm5wJTIyJTJDJTIwcGFkZGluZyUzRFRydWUpJTBBJTIzJTIwVG9rZW5pemVyJTIwcmV0dXJucyUyMGElMjBCYXRjaEVuY29kaW5nJTJDJTIwYnV0JTIwd2UlMjBjb252ZXJ0JTIwdGhhdCUyMHRvJTIwYSUyMGRpY3QlMjBmb3IlMjBLZXJhcyUwQXRva2VuaXplZF9kYXRhJTIwJTNEJTIwZGljdCh0b2tlbml6ZWRfZGF0YSklMEElMEFsYWJlbHMlMjAlM0QlMjBucC5hcnJheShkYXRhc2V0JTVCJTIybGFiZWwlMjIlNUQpJTIwJTIwJTIzJTIwTGFiZWwlMjBpcyUyMGFscmVhZHklMjBhbiUyMGFycmF5JTIwb2YlMjAwJTIwYW5kJTIwMQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>)
tokenized_data = tokenizer(dataset[<span class="hljs-string">&quot;sentence&quot;</span>], return_tensors=<span class="hljs-string">&quot;np&quot;</span>, padding=<span class="hljs-literal">True</span>)
<span class="hljs-comment"># Tokenizer returns a BatchEncoding, but we convert that to a dict for Keras</span>
tokenized_data = <span class="hljs-built_in">dict</span>(tokenized_data)

labels = np.array(dataset[<span class="hljs-string">&quot;label&quot;</span>])  <span class="hljs-comment"># Label is already an array of 0 and 1</span>`,wrap:!1}}),I=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQWZyb20lMjB0ZW5zb3JmbG93LmtlcmFzLm9wdGltaXplcnMlMjBpbXBvcnQlMjBBZGFtJTBBJTBBJTIzJTIwTG9hZCUyMGFuZCUyMGNvbXBpbGUlMjBvdXIlMjBtb2RlbCUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUtYmVydCUyRmJlcnQtYmFzZS1jYXNlZCUyMiklMEElMjMlMjBMb3dlciUyMGxlYXJuaW5nJTIwcmF0ZXMlMjBhcmUlMjBvZnRlbiUyMGJldHRlciUyMGZvciUyMGZpbmUtdHVuaW5nJTIwdHJhbnNmb3JtZXJzJTBBbW9kZWwuY29tcGlsZShvcHRpbWl6ZXIlM0RBZGFtKDNlLTUpKSUwQSUwQW1vZGVsLmZpdCh0b2tlbml6ZWRfZGF0YSUyQyUyMGxhYmVscyk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification
<span class="hljs-keyword">from</span> tensorflow.keras.optimizers <span class="hljs-keyword">import</span> Adam

<span class="hljs-comment"># Load and compile our model</span>
model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>)
<span class="hljs-comment"># Lower learning rates are often better for fine-tuning transformers</span>
model.<span class="hljs-built_in">compile</span>(optimizer=Adam(<span class="hljs-number">3e-5</span>))

model.fit(tokenized_data, labels)`,wrap:!1}}),K=new ee({props:{$$slots:{default:[ue]},$$scope:{ctx:dt}}}),O=new Zt({props:{title:"데이터를 tf.data.Dataset으로 로드하기",local:"loading-data-as-a-tfdatadataset",headingTag:"h3"}}),N=new G({props:{code:"ZGVmJTIwdG9rZW5pemVfZGF0YXNldChkYXRhKSUzQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEtleXMlMjBvZiUyMHRoZSUyMHJldHVybmVkJTIwZGljdGlvbmFyeSUyMHdpbGwlMjBiZSUyMGFkZGVkJTIwdG8lMjB0aGUlMjBkYXRhc2V0JTIwYXMlMjBjb2x1bW5zJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdG9rZW5pemVyKGRhdGElNUIlMjJ0ZXh0JTIyJTVEKSUwQSUwQSUwQWRhdGFzZXQlMjAlM0QlMjBkYXRhc2V0Lm1hcCh0b2tlbml6ZV9kYXRhc2V0KQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_dataset</span>(<span class="hljs-params">data</span>):
    <span class="hljs-comment"># Keys of the returned dictionary will be added to the dataset as columns</span>
    <span class="hljs-keyword">return</span> tokenizer(data[<span class="hljs-string">&quot;text&quot;</span>])


dataset = dataset.<span class="hljs-built_in">map</span>(tokenize_dataset)`,wrap:!1}}),st=new G({props:{code:"dGZfZGF0YXNldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldChkYXRhc2V0JTJDJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTIwc2h1ZmZsZSUzRFRydWUlMkMlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tf_dataset = model.prepare_tf_dataset(dataset, batch_size=<span class="hljs-number">16</span>, shuffle=<span class="hljs-literal">True</span>, tokenizer=tokenizer)',wrap:!1}}),jt=new G({props:{code:"bW9kZWwuY29tcGlsZShvcHRpbWl6ZXIlM0RBZGFtKDNlLTUpKSUwQSUwQW1vZGVsLmZpdCh0Zl9kYXRhc2V0KQ==",highlighted:`model.<span class="hljs-built_in">compile</span>(optimizer=Adam(<span class="hljs-number">3e-5</span>))

model.fit(tf_dataset)`,wrap:!1}}),{c(){i=h("a"),T=r(),u(m.$$.fragment),J=r(),u(k.$$.fragment),nt=r(),A=h("p"),A.textContent=rt,L=r(),u(pt.$$.fragment),R=r(),Q=h("p"),Q.textContent=ct,W=r(),U=h("p"),U.innerHTML=ht,q=r(),u(Mt.$$.fragment),X=r(),H=h("p"),H.textContent=at,ut=r(),u(S.$$.fragment),$t=r(),P=h("p"),P.innerHTML=gt,V=r(),u(I.$$.fragment),it=r(),u(K.$$.fragment),mt=r(),x=h("p"),x.textContent=D,ot=r(),u(O.$$.fragment),ft=r(),F=h("p"),F.innerHTML=tt,lt=r(),v=h("ul"),v.innerHTML=kt,yt=r(),Z=h("p"),Z.innerHTML=Ut,z=r(),u(N.$$.fragment),et=r(),Y=h("p"),Y.textContent=Tt,C=r(),u(st.$$.fragment),_=r(),bt=h("p"),bt.innerHTML=wt,B=r(),E=h("p"),E.innerHTML=l,d=r(),u(jt.$$.fragment),this.h()},l(n){i=M(n,"A",{id:!0}),It(i).forEach(e),T=p(n),$(m.$$.fragment,n),J=p(n),$(k.$$.fragment,n),nt=p(n),A=M(n,"P",{"data-svelte-h":!0}),j(A)!=="svelte-ze9716"&&(A.textContent=rt),L=p(n),$(pt.$$.fragment,n),R=p(n),Q=M(n,"P",{"data-svelte-h":!0}),j(Q)!=="svelte-15pnkld"&&(Q.textContent=ct),W=p(n),U=M(n,"P",{"data-svelte-h":!0}),j(U)!=="svelte-1u2iume"&&(U.innerHTML=ht),q=p(n),$(Mt.$$.fragment,n),X=p(n),H=M(n,"P",{"data-svelte-h":!0}),j(H)!=="svelte-kduu5a"&&(H.textContent=at),ut=p(n),$(S.$$.fragment,n),$t=p(n),P=M(n,"P",{"data-svelte-h":!0}),j(P)!=="svelte-1mtm6sq"&&(P.innerHTML=gt),V=p(n),$(I.$$.fragment,n),it=p(n),$(K.$$.fragment,n),mt=p(n),x=M(n,"P",{"data-svelte-h":!0}),j(x)!=="svelte-1ggdj2"&&(x.textContent=D),ot=p(n),$(O.$$.fragment,n),ft=p(n),F=M(n,"P",{"data-svelte-h":!0}),j(F)!=="svelte-5ru8h1"&&(F.innerHTML=tt),lt=p(n),v=M(n,"UL",{"data-svelte-h":!0}),j(v)!=="svelte-1ira4w9"&&(v.innerHTML=kt),yt=p(n),Z=M(n,"P",{"data-svelte-h":!0}),j(Z)!=="svelte-k3j62x"&&(Z.innerHTML=Ut),z=p(n),$(N.$$.fragment,n),et=p(n),Y=M(n,"P",{"data-svelte-h":!0}),j(Y)!=="svelte-10zjmdj"&&(Y.textContent=Tt),C=p(n),$(st.$$.fragment,n),_=p(n),bt=M(n,"P",{"data-svelte-h":!0}),j(bt)!=="svelte-1k6j3lz"&&(bt.innerHTML=wt),B=p(n),E=M(n,"P",{"data-svelte-h":!0}),j(E)!=="svelte-zwzwju"&&(E.innerHTML=l),d=p(n),$(jt.$$.fragment,n),this.h()},h(){Ht(i,"id","keras")},m(n,c){a(n,i,c),a(n,T,c),g(m,n,c),a(n,J,c),g(k,n,c),a(n,nt,c),a(n,A,c),a(n,L,c),g(pt,n,c),a(n,R,c),a(n,Q,c),a(n,W,c),a(n,U,c),a(n,q,c),g(Mt,n,c),a(n,X,c),a(n,H,c),a(n,ut,c),g(S,n,c),a(n,$t,c),a(n,P,c),a(n,V,c),g(I,n,c),a(n,it,c),g(K,n,c),a(n,mt,c),a(n,x,c),a(n,ot,c),g(O,n,c),a(n,ft,c),a(n,F,c),a(n,lt,c),a(n,v,c),a(n,yt,c),a(n,Z,c),a(n,z,c),g(N,n,c),a(n,et,c),a(n,Y,c),a(n,C,c),g(st,n,c),a(n,_,c),a(n,bt,c),a(n,B,c),a(n,E,c),a(n,d,c),g(jt,n,c),Jt=!0},p(n,c){const Rt={};c&2&&(Rt.$$scope={dirty:c,ctx:n}),K.$set(Rt)},i(n){Jt||(y(m.$$.fragment,n),y(k.$$.fragment,n),y(pt.$$.fragment,n),y(Mt.$$.fragment,n),y(S.$$.fragment,n),y(I.$$.fragment,n),y(K.$$.fragment,n),y(O.$$.fragment,n),y(N.$$.fragment,n),y(st.$$.fragment,n),y(jt.$$.fragment,n),Jt=!0)},o(n){w(m.$$.fragment,n),w(k.$$.fragment,n),w(pt.$$.fragment,n),w(Mt.$$.fragment,n),w(S.$$.fragment,n),w(I.$$.fragment,n),w(K.$$.fragment,n),w(O.$$.fragment,n),w(N.$$.fragment,n),w(st.$$.fragment,n),w(jt.$$.fragment,n),Jt=!1},d(n){n&&(e(i),e(T),e(J),e(nt),e(A),e(L),e(R),e(Q),e(W),e(U),e(q),e(X),e(H),e(ut),e($t),e(P),e(V),e(it),e(mt),e(x),e(ot),e(ft),e(F),e(lt),e(v),e(yt),e(Z),e(z),e(et),e(Y),e(C),e(_),e(bt),e(B),e(E),e(d)),b(m,n),b(k,n),b(pt,n),b(Mt,n),b(S,n),b(I,n),b(K,n),b(O,n),b(N,n),b(st,n),b(jt,n)}}}function ge(dt){let i,T;return i=new se({props:{$$slots:{default:[$e]},$$scope:{ctx:dt}}}),{c(){u(i.$$.fragment)},l(m){$(i.$$.fragment,m)},m(m,J){g(i,m,J),T=!0},p(m,J){const k={};J&2&&(k.$$scope={dirty:J,ctx:m}),i.$set(k)},i(m){T||(y(i.$$.fragment,m),T=!0)},o(m){w(i.$$.fragment,m),T=!1},d(m){b(i,m)}}}function ye(dt){let i,T='<a href="https://colab.research.google.com/" rel="nofollow">Colaboratory</a> 또는 <a href="https://studiolab.sagemaker.aws/" rel="nofollow">SageMaker StudioLab</a>과 같은 호스팅 노트북이 없는 경우 클라우드 GPU에 무료로 액세스할 수 있습니다.';return{c(){i=h("p"),i.innerHTML=T},l(m){i=M(m,"P",{"data-svelte-h":!0}),j(i)!=="svelte-1ctkiwu"&&(i.innerHTML=T)},m(m,J){a(m,i,J)},p:te,d(m){m&&e(i)}}}function we(dt){let i,T,m,J='<a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>는 훈련 루프를 처리하며 한 줄의 코드로 모델을 미세 조정할 수 있습니다. 직접 훈련 루프를 작성하는 것을 선호하는 사용자의 경우, 기본 PyTorch에서 🤗 Transformers 모델을 미세 조정할 수도 있습니다.',k,nt,A="이 시점에서 노트북을 다시 시작하거나 다음 코드를 실행해 메모리를 확보해야 할 수 있습니다:",rt,L,pt,R,Q="다음으로, ‘토큰화된 데이터셋’을 수동으로 후처리하여 훈련련에 사용할 수 있도록 준비합니다.",ct,W,U,ht,q="모델이 원시 텍스트를 입력으로 허용하지 않으므로 <code>text</code> 열을 제거합니다:",Mt,X,H,at,ut,S="모델에서 인수의 이름이 <code>labels</code>로 지정될 것으로 예상하므로 <code>label</code> 열의 이름을 <code>labels</code>로 변경합니다:",$t,P,gt,V,I,it="데이터셋의 형식을 List 대신 PyTorch 텐서를 반환하도록 설정합니다:",K,mt,x,D,ot="그리고 앞서 표시된 대로 데이터셋의 더 작은 하위 집합을 생성하여 미세 조정 속도를 높입니다:",O,ft,F,tt,lt,v,kt="훈련 및 테스트 데이터셋에 대한 ‘DataLoader’를 생성하여 데이터 배치를 반복할 수 있습니다:",yt,Z,Ut,z,N="예측을 위한 레이블 개수를 사용하여 모델을 로드합니다:",et,Y,Tt,C,st,_,bt='옵티마이저와 학습 속도 스케줄러를 생성하여 모델을 미세 조정합니다. 파이토치에서 제공하는 <a href="https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html" rel="nofollow"><code>AdamW</code></a> 옵티마이저를 사용해 보겠습니다:',wt,B,E,l,d='<a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>에서 기본 학습 속도 스케줄러를 생성합니다:',jt,Jt,n,c,Rt="마지막으로, GPU에 액세스할 수 있는 경우 ‘device’를 지정하여 GPU를 사용하도록 합니다. 그렇지 않으면 CPU에서 훈련하며 몇 분이 아닌 몇 시간이 걸릴 수 있습니다.",vt,Ct,Wt,_t,s,o,Nt="이제 훈련할 준비가 되었습니다! 🥳",Xt,Vt,At,xt,ae='훈련 진행 상황을 추적하려면 <a href="https://tqdm.github.io/" rel="nofollow">tqdm</a> 라이브러리를 사용하여 트레이닝 단계 수에 진행률 표시줄을 추가하세요:',Lt,Ft,Qt,zt,qt,Yt,le='<a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>에 평가 함수를 추가한 방법과 마찬가지로, 훈련 루프를 직접 작성할 때도 동일한 작업을 수행해야 합니다. 하지만 이번에는 각 에포크가 끝날 때마다 평가지표를 계산하여 보고하는 대신, <code>add_batch</code>를 사용하여 모든 배치를 누적하고 맨 마지막에 평가지표를 계산합니다.',St,Bt,Pt;return i=new Ot({props:{id:"Dh9CL8fyG80"}}),L=new G({props:{code:"ZGVsJTIwbW9kZWwlMEFkZWwlMjB0cmFpbmVyJTBBdG9yY2guY3VkYS5lbXB0eV9jYWNoZSgp",highlighted:`<span class="hljs-keyword">del</span> model
<span class="hljs-keyword">del</span> trainer
torch.cuda.empty_cache()`,wrap:!1}}),X=new G({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbW92ZV9jb2x1bW5zKCU1QiUyMnRleHQlMjIlNUQp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = tokenized_datasets.remove_columns([<span class="hljs-string">&quot;text&quot;</span>])',wrap:!1}}),P=new G({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbmFtZV9jb2x1bW4oJTIybGFiZWwlMjIlMkMlMjAlMjJsYWJlbHMlMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = tokenized_datasets.rename_column(<span class="hljs-string">&quot;label&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>)',wrap:!1}}),mt=new G({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)',wrap:!1}}),ft=new G({props:{code:"c21hbGxfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnNodWZmbGUoc2VlZCUzRDQyKS5zZWxlY3QocmFuZ2UoMTAwMCkpJTBBc21hbGxfZXZhbF9kYXRhc2V0JTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydGVzdCUyMiU1RC5zaHVmZmxlKHNlZWQlM0Q0Mikuc2VsZWN0KHJhbmdlKDEwMDApKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>small_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>small_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;test&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))`,wrap:!1}}),tt=new Zt({props:{title:"DataLoader",local:"dataloader",headingTag:"h3"}}),Z=new G({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBdHJhaW5fZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoc21hbGxfdHJhaW5fZGF0YXNldCUyQyUyMHNodWZmbGUlM0RUcnVlJTJDJTIwYmF0Y2hfc2l6ZSUzRDgpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlcihzbWFsbF9ldmFsX2RhdGFzZXQlMkMlMjBiYXRjaF9zaXplJTNEOCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

<span class="hljs-meta">&gt;&gt;&gt; </span>train_dataloader = DataLoader(small_train_dataset, shuffle=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">8</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>eval_dataloader = DataLoader(small_eval_dataset, batch_size=<span class="hljs-number">8</span>)`,wrap:!1}}),Y=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZS1iZXJ0JTJGYmVydC1iYXNlLWNhc2VkJTIyJTJDJTIwbnVtX2xhYmVscyUzRDUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>, num_labels=<span class="hljs-number">5</span>)`,wrap:!1}}),C=new Zt({props:{title:"옵티마이저 및 학습 속도 스케줄러",local:"optimizer-and-learning-rate-scheduler",headingTag:"h3"}}),B=new G({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDVlLTUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">5e-5</span>)`,wrap:!1}}),Jt=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV90cmFpbmluZ19zdGVwcyUyMCUzRCUyMG51bV9lcG9jaHMlMjAqJTIwbGVuKHRyYWluX2RhdGFsb2FkZXIpJTBBbHJfc2NoZWR1bGVyJTIwJTNEJTIwZ2V0X3NjaGVkdWxlciglMEElMjAlMjAlMjAlMjBuYW1lJTNEJTIybGluZWFyJTIyJTJDJTIwb3B0aW1pemVyJTNEb3B0aW1pemVyJTJDJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMjBudW1fdHJhaW5pbmdfc3RlcHMlM0RudW1fdHJhaW5pbmdfc3RlcHMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">3</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dataloader)
<span class="hljs-meta">&gt;&gt;&gt; </span>lr_scheduler = get_scheduler(
<span class="hljs-meta">... </span>    name=<span class="hljs-string">&quot;linear&quot;</span>, optimizer=optimizer, num_warmup_steps=<span class="hljs-number">0</span>, num_training_steps=num_training_steps
<span class="hljs-meta">... </span>)`,wrap:!1}}),Ct=new G({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFkZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3VkYSUyMiklMjBpZiUyMHRvcmNoLmN1ZGEuaXNfYXZhaWxhYmxlKCklMjBlbHNlJTIwdG9yY2guZGV2aWNlKCUyMmNwdSUyMiklMEFtb2RlbC50byhkZXZpY2Up",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>device = torch.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> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.to(device)`,wrap:!1}}),_t=new ee({props:{$$slots:{default:[ye]},$$scope:{ctx:dt}}}),Vt=new Zt({props:{title:"훈련 루프",local:"training-loop",headingTag:"h3"}}),Ft=new G({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEElMEFwcm9ncmVzc19iYXIlMjAlM0QlMjB0cWRtKHJhbmdlKG51bV90cmFpbmluZ19zdGVwcykpJTBBJTBBbW9kZWwudHJhaW4oKSUwQWZvciUyMGVwb2NoJTIwaW4lMjByYW5nZShudW1fZXBvY2hzKSUzQSUwQSUyMCUyMCUyMCUyMGZvciUyMGJhdGNoJTIwaW4lMjB0cmFpbl9kYXRhbG9hZGVyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYmF0Y2glMjAlM0QlMjAlN0JrJTNBJTIwdi50byhkZXZpY2UpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGJhdGNoLml0ZW1zKCklN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKipiYXRjaCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwb3V0cHV0cy5sb3NzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbG9zcy5iYWNrd2FyZCgpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnN0ZXAoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxyX3NjaGVkdWxlci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcHRpbWl6ZXIuemVyb19ncmFkKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcm9ncmVzc19iYXIudXBkYXRlKDEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm

<span class="hljs-meta">&gt;&gt;&gt; </span>progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

<span class="hljs-meta">&gt;&gt;&gt; </span>model.train()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
<span class="hljs-meta">... </span>        batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
<span class="hljs-meta">... </span>        outputs = model(**batch)
<span class="hljs-meta">... </span>        loss = outputs.loss
<span class="hljs-meta">... </span>        loss.backward()

<span class="hljs-meta">... </span>        optimizer.step()
<span class="hljs-meta">... </span>        lr_scheduler.step()
<span class="hljs-meta">... </span>        optimizer.zero_grad()
<span class="hljs-meta">... </span>        progress_bar.update(<span class="hljs-number">1</span>)`,wrap:!1}}),zt=new Zt({props:{title:"평가 하기",local:"evaluate",headingTag:"h3"}}),Bt=new G({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmFjY3VyYWN5JTIyKSUwQW1vZGVsLmV2YWwoKSUwQWZvciUyMGJhdGNoJTIwaW4lMjBldmFsX2RhdGFsb2FkZXIlM0ElMEElMjAlMjAlMjAlMjBiYXRjaCUyMCUzRCUyMCU3QmslM0ElMjB2LnRvKGRldmljZSklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwYmF0Y2guaXRlbXMoKSU3RCUwQSUyMCUyMCUyMCUyMHdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKipiYXRjaCklMEElMEElMjAlMjAlMjAlMjBsb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmxvZ2l0cyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwdG9yY2guYXJnbWF4KGxvZ2l0cyUyQyUyMGRpbSUzRC0xKSUwQSUyMCUyMCUyMCUyMG1ldHJpYy5hZGRfYmF0Y2gocHJlZGljdGlvbnMlM0RwcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0RiYXRjaCU1QiUyMmxhYmVscyUyMiU1RCklMEElMEFtZXRyaWMuY29tcHV0ZSgp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">eval</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
<span class="hljs-meta">... </span>    batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>        outputs = model(**batch)

<span class="hljs-meta">... </span>    logits = outputs.logits
<span class="hljs-meta">... </span>    predictions = torch.argmax(logits, dim=-<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    metric.add_batch(predictions=predictions, references=batch[<span class="hljs-string">&quot;labels&quot;</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>metric.compute()`,wrap:!1}}),{c(){u(i.$$.fragment),T=r(),m=h("p"),m.innerHTML=J,k=r(),nt=h("p"),nt.textContent=A,rt=r(),u(L.$$.fragment),pt=r(),R=h("p"),R.textContent=Q,ct=r(),W=h("ol"),U=h("li"),ht=h("p"),ht.innerHTML=q,Mt=r(),u(X.$$.fragment),H=r(),at=h("li"),ut=h("p"),ut.innerHTML=S,$t=r(),u(P.$$.fragment),gt=r(),V=h("li"),I=h("p"),I.textContent=it,K=r(),u(mt.$$.fragment),x=r(),D=h("p"),D.textContent=ot,O=r(),u(ft.$$.fragment),F=r(),u(tt.$$.fragment),lt=r(),v=h("p"),v.textContent=kt,yt=r(),u(Z.$$.fragment),Ut=r(),z=h("p"),z.textContent=N,et=r(),u(Y.$$.fragment),Tt=r(),u(C.$$.fragment),st=r(),_=h("p"),_.innerHTML=bt,wt=r(),u(B.$$.fragment),E=r(),l=h("p"),l.innerHTML=d,jt=r(),u(Jt.$$.fragment),n=r(),c=h("p"),c.textContent=Rt,vt=r(),u(Ct.$$.fragment),Wt=r(),u(_t.$$.fragment),s=r(),o=h("p"),o.textContent=Nt,Xt=r(),u(Vt.$$.fragment),At=r(),xt=h("p"),xt.innerHTML=ae,Lt=r(),u(Ft.$$.fragment),Qt=r(),u(zt.$$.fragment),qt=r(),Yt=h("p"),Yt.innerHTML=le,St=r(),u(Bt.$$.fragment)},l(t){$(i.$$.fragment,t),T=p(t),m=M(t,"P",{"data-svelte-h":!0}),j(m)!=="svelte-1r6wrv4"&&(m.innerHTML=J),k=p(t),nt=M(t,"P",{"data-svelte-h":!0}),j(nt)!=="svelte-192c5yp"&&(nt.textContent=A),rt=p(t),$(L.$$.fragment,t),pt=p(t),R=M(t,"P",{"data-svelte-h":!0}),j(R)!=="svelte-108uveq"&&(R.textContent=Q),ct=p(t),W=M(t,"OL",{});var f=It(W);U=M(f,"LI",{});var Et=It(U);ht=M(Et,"P",{"data-svelte-h":!0}),j(ht)!=="svelte-1y5q08j"&&(ht.innerHTML=q),Mt=p(Et),$(X.$$.fragment,Et),Et.forEach(e),H=p(f),at=M(f,"LI",{});var Kt=It(at);ut=M(Kt,"P",{"data-svelte-h":!0}),j(ut)!=="svelte-1j9nsiy"&&(ut.innerHTML=S),$t=p(Kt),$(P.$$.fragment,Kt),Kt.forEach(e),gt=p(f),V=M(f,"LI",{});var Dt=It(V);I=M(Dt,"P",{"data-svelte-h":!0}),j(I)!=="svelte-1h9qay5"&&(I.textContent=it),K=p(Dt),$(mt.$$.fragment,Dt),Dt.forEach(e),f.forEach(e),x=p(t),D=M(t,"P",{"data-svelte-h":!0}),j(D)!=="svelte-hdideh"&&(D.textContent=ot),O=p(t),$(ft.$$.fragment,t),F=p(t),$(tt.$$.fragment,t),lt=p(t),v=M(t,"P",{"data-svelte-h":!0}),j(v)!=="svelte-1ektf94"&&(v.textContent=kt),yt=p(t),$(Z.$$.fragment,t),Ut=p(t),z=M(t,"P",{"data-svelte-h":!0}),j(z)!=="svelte-sqozl7"&&(z.textContent=N),et=p(t),$(Y.$$.fragment,t),Tt=p(t),$(C.$$.fragment,t),st=p(t),_=M(t,"P",{"data-svelte-h":!0}),j(_)!=="svelte-15zsq6h"&&(_.innerHTML=bt),wt=p(t),$(B.$$.fragment,t),E=p(t),l=M(t,"P",{"data-svelte-h":!0}),j(l)!=="svelte-bn1bep"&&(l.innerHTML=d),jt=p(t),$(Jt.$$.fragment,t),n=p(t),c=M(t,"P",{"data-svelte-h":!0}),j(c)!=="svelte-e6t5r4"&&(c.textContent=Rt),vt=p(t),$(Ct.$$.fragment,t),Wt=p(t),$(_t.$$.fragment,t),s=p(t),o=M(t,"P",{"data-svelte-h":!0}),j(o)!=="svelte-1yeeebv"&&(o.textContent=Nt),Xt=p(t),$(Vt.$$.fragment,t),At=p(t),xt=M(t,"P",{"data-svelte-h":!0}),j(xt)!=="svelte-1atq943"&&(xt.innerHTML=ae),Lt=p(t),$(Ft.$$.fragment,t),Qt=p(t),$(zt.$$.fragment,t),qt=p(t),Yt=M(t,"P",{"data-svelte-h":!0}),j(Yt)!=="svelte-1in5av8"&&(Yt.innerHTML=le),St=p(t),$(Bt.$$.fragment,t)},m(t,f){g(i,t,f),a(t,T,f),a(t,m,f),a(t,k,f),a(t,nt,f),a(t,rt,f),g(L,t,f),a(t,pt,f),a(t,R,f),a(t,ct,f),a(t,W,f),Gt(W,U),Gt(U,ht),Gt(U,Mt),g(X,U,null),Gt(W,H),Gt(W,at),Gt(at,ut),Gt(at,$t),g(P,at,null),Gt(W,gt),Gt(W,V),Gt(V,I),Gt(V,K),g(mt,V,null),a(t,x,f),a(t,D,f),a(t,O,f),g(ft,t,f),a(t,F,f),g(tt,t,f),a(t,lt,f),a(t,v,f),a(t,yt,f),g(Z,t,f),a(t,Ut,f),a(t,z,f),a(t,et,f),g(Y,t,f),a(t,Tt,f),g(C,t,f),a(t,st,f),a(t,_,f),a(t,wt,f),g(B,t,f),a(t,E,f),a(t,l,f),a(t,jt,f),g(Jt,t,f),a(t,n,f),a(t,c,f),a(t,vt,f),g(Ct,t,f),a(t,Wt,f),g(_t,t,f),a(t,s,f),a(t,o,f),a(t,Xt,f),g(Vt,t,f),a(t,At,f),a(t,xt,f),a(t,Lt,f),g(Ft,t,f),a(t,Qt,f),g(zt,t,f),a(t,qt,f),a(t,Yt,f),a(t,St,f),g(Bt,t,f),Pt=!0},p(t,f){const Et={};f&2&&(Et.$$scope={dirty:f,ctx:t}),_t.$set(Et)},i(t){Pt||(y(i.$$.fragment,t),y(L.$$.fragment,t),y(X.$$.fragment,t),y(P.$$.fragment,t),y(mt.$$.fragment,t),y(ft.$$.fragment,t),y(tt.$$.fragment,t),y(Z.$$.fragment,t),y(Y.$$.fragment,t),y(C.$$.fragment,t),y(B.$$.fragment,t),y(Jt.$$.fragment,t),y(Ct.$$.fragment,t),y(_t.$$.fragment,t),y(Vt.$$.fragment,t),y(Ft.$$.fragment,t),y(zt.$$.fragment,t),y(Bt.$$.fragment,t),Pt=!0)},o(t){w(i.$$.fragment,t),w(L.$$.fragment,t),w(X.$$.fragment,t),w(P.$$.fragment,t),w(mt.$$.fragment,t),w(ft.$$.fragment,t),w(tt.$$.fragment,t),w(Z.$$.fragment,t),w(Y.$$.fragment,t),w(C.$$.fragment,t),w(B.$$.fragment,t),w(Jt.$$.fragment,t),w(Ct.$$.fragment,t),w(_t.$$.fragment,t),w(Vt.$$.fragment,t),w(Ft.$$.fragment,t),w(zt.$$.fragment,t),w(Bt.$$.fragment,t),Pt=!1},d(t){t&&(e(T),e(m),e(k),e(nt),e(rt),e(pt),e(R),e(ct),e(W),e(x),e(D),e(O),e(F),e(lt),e(v),e(yt),e(Ut),e(z),e(et),e(Tt),e(st),e(_),e(wt),e(E),e(l),e(jt),e(n),e(c),e(vt),e(Wt),e(s),e(o),e(Xt),e(At),e(xt),e(Lt),e(Qt),e(qt),e(Yt),e(St)),b(i,t),b(L,t),b(X),b(P),b(mt),b(ft,t),b(tt,t),b(Z,t),b(Y,t),b(C,t),b(B,t),b(Jt,t),b(Ct,t),b(_t,t),b(Vt,t),b(Ft,t),b(zt,t),b(Bt,t)}}}function be(dt){let i,T;return i=new se({props:{$$slots:{default:[we]},$$scope:{ctx:dt}}}),{c(){u(i.$$.fragment)},l(m){$(i.$$.fragment,m)},m(m,J){g(i,m,J),T=!0},p(m,J){const k={};J&2&&(k.$$scope={dirty:J,ctx:m}),i.$set(k)},i(m){T||(y(i.$$.fragment,m),T=!0)},o(m){w(i.$$.fragment,m),T=!1},d(m){b(i,m)}}}function je(dt){let i,T,m,J,k,nt,A,rt,L,pt="사전 학습된 모델을 사용하면 상당한 이점이 있습니다. 계산 비용과 탄소발자국을 줄이고, 처음부터 모델을 학습시킬 필요 없이 최신 모델을 사용할 수 있습니다. 🤗 Transformers는 다양한 작업을 위해 사전 학습된 수천 개의 모델에 액세스할 수 있습니다. 사전 학습된 모델을 사용하는 경우, 자신의 작업과 관련된 데이터셋을 사용해 학습합니다. 이것은 미세 튜닝이라고 하는 매우 강력한 훈련 기법입니다. 이 튜토리얼에서는 당신이 선택한 딥러닝 프레임워크로 사전 학습된 모델을 미세 튜닝합니다:",R,Q,ct='<li>🤗 Transformers로 사전 학습된 모델 미세 튜닝하기 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>.</li> <li>Keras를 사용하여 TensorFlow에서 사전 학습된 모델을 미세 튜닝하기.</li> <li>기본 PyTorch에서 사전 학습된 모델을 미세 튜닝하기.</li>',W,U,ht,q,Mt,X,H,at,ut="사전 학습된 모델을 미세 튜닝하기 위해서 데이터셋을 다운로드하고 훈련할 수 있도록 준비하세요. 이전 튜토리얼에서 훈련을 위해 데이터를 처리하는 방법을 보여드렸는데, 지금이 배울 걸 되짚을 기회입니다!",S,$t,P='먼저 <a href="https://huggingface.co/datasets/yelp_review_full" rel="nofollow">Yelp 리뷰</a> 데이터 세트를 로드합니다:',gt,V,I,it,K='텍스트를 처리하고 서로 다른 길이의 시퀀스 패딩 및 잘라내기 전략을 포함하려면 토크나이저가 필요합니다. 데이터셋을 한 번에 처리하려면 🤗 Dataset <a href="https://huggingface.co/docs/datasets/process#map" rel="nofollow"><code>map</code></a> 메서드를 사용하여 전체 데이터셋에 전처리 함수를 적용하세요:',mt,x,D,ot,O="필요한 경우 미세 튜닝을 위해 데이터셋의 작은 부분 집합을 만들어 미세 튜닝 작업 시간을 줄일 수 있습니다:",ft,F,tt,lt,v,kt,yt,Z,Ut="여기서부터는 사용하려는 프레임워크에 해당하는 섹션을 따라야 합니다. 오른쪽 사이드바의 링크를 사용하여 원하는 프레임워크로 이동할 수 있으며, 특정 프레임워크의 모든 콘텐츠를 숨기려면 해당 프레임워크 블록의 오른쪽 상단에 있는 버튼을 사용하면 됩니다!",z,N,et,Y,Tt,C,st,_,bt,wt,B,E,l,d,jt="더 많은 미세 튜닝 예제는 다음을 참조하세요:",Jt,n,c='<li><p><a href="https://github.com/huggingface/transformers/tree/main/examples" rel="nofollow">🤗 Trnasformers 예제</a>에는 PyTorch 및 텐서플로우에서 일반적인 NLP 작업을 훈련할 수 있는 스크립트가 포함되어 있습니다.</p></li> <li><p><a href="notebooks">🤗 Transformers 노트북</a>에는 PyTorch 및 텐서플로우에서 특정 작업을 위해 모델을 미세 튜닝하는 방법에 대한 다양한 노트북이 포함되어 있습니다.</p></li>',Rt,vt,Ct,Wt,_t;return k=new Zt({props:{title:"사전 학습된 모델 미세 튜닝하기",local:"finetune-a-pretrained-model",headingTag:"h1"}}),A=new fe({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/training.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/tensorflow/training.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/training.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/tensorflow/training.ipynb"}]}}),q=new Zt({props:{title:"데이터셋 준비",local:"prepare-a-dataset",headingTag:"h2"}}),X=new Ot({props:{id:"_BZearw7f0w"}}),V=new G({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJ5ZWxwX3Jldmlld19mdWxsJTIyKSUwQWRhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCU1QjEwMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;yelp_review_full&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">100</span>]
{<span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">0</span>,
 <span class="hljs-string">&#x27;text&#x27;</span>: <span class="hljs-string">&#x27;My expectations for McDonalds are t rarely high. But for one to still fail so spectacularly...that takes something special!\\\\nThe cashier took my friends\\&#x27;s order, then promptly ignored me. I had to force myself in front of a cashier who opened his register to wait on the person BEHIND me. I waited over five minutes for a gigantic order that included precisely one kid\\&#x27;s meal. After watching two people who ordered after me be handed their food, I asked where mine was. The manager started yelling at the cashiers for \\\\&quot;serving off their orders\\\\&quot; when they didn\\&#x27;t have their food. But neither cashier was anywhere near those controls, and the manager was the one serving food to customers and clearing the boards.\\\\nThe manager was rude when giving me my order. She didn\\&#x27;t make sure that I had everything ON MY RECEIPT, and never even had the decency to apologize that I felt I was getting poor service.\\\\nI\\&#x27;ve eaten at various McDonalds restaurants for over 30 years. I\\&#x27;ve worked at more than one location. I expect bad days, bad moods, and the occasional mistake. But I have yet to have a decent experience at this store. It will remain a place I avoid unless someone in my party needs to avoid illness from low blood sugar. Perhaps I should go back to the racially biased service of Steak n Shake instead!&#x27;</span>}`,wrap:!1}}),x=new G({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUtYmVydCUyRmJlcnQtYmFzZS1jYXNlZCUyMiklMEElMEElMEFkZWYlMjB0b2tlbml6ZV9mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIoZXhhbXBsZXMlNUIlMjJ0ZXh0JTIyJTVEJTJDJTIwcGFkZGluZyUzRCUyMm1heF9sZW5ndGglMjIlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSklMEElMEElMEF0b2tlbml6ZWRfZGF0YXNldHMlMjAlM0QlMjBkYXRhc2V0Lm1hcCh0b2tlbml6ZV9mdW5jdGlvbiUyQyUyMGJhdGNoZWQlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google-bert/bert-base-cased&quot;</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>], padding=<span class="hljs-string">&quot;max_length&quot;</span>, truncation=<span class="hljs-literal">True</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = dataset.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)`,wrap:!1}}),F=new G({props:{code:"c21hbGxfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnNodWZmbGUoc2VlZCUzRDQyKS5zZWxlY3QocmFuZ2UoMTAwMCkpJTBBc21hbGxfZXZhbF9kYXRhc2V0JTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydGVzdCUyMiU1RC5zaHVmZmxlKHNlZWQlM0Q0Mikuc2VsZWN0KHJhbmdlKDEwMDApKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>small_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>small_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;test&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))`,wrap:!1}}),kt=new Zt({props:{title:"Train",local:"train",headingTag:"h2"}}),N=new ne({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ge],pytorch:[Me]},$$scope:{ctx:dt}}}),C=new Zt({props:{title:"기본 파이토치로 훈련하기",local:"train-in-native-pytorch",headingTag:"h2"}}),_=new ne({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[be]},$$scope:{ctx:dt}}}),E=new Zt({props:{title:"추가 자료",local:"additional-resources",headingTag:"h2"}}),vt=new de({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/training.md"}}),{c(){i=h("meta"),T=r(),m=h("p"),J=r(),u(k.$$.fragment),nt=r(),u(A.$$.fragment),rt=r(),L=h("p"),L.textContent=pt,R=r(),Q=h("ul"),Q.innerHTML=ct,W=r(),U=h("a"),ht=r(),u(q.$$.fragment),Mt=r(),u(X.$$.fragment),H=r(),at=h("p"),at.textContent=ut,S=r(),$t=h("p"),$t.innerHTML=P,gt=r(),u(V.$$.fragment),I=r(),it=h("p"),it.innerHTML=K,mt=r(),u(x.$$.fragment),D=r(),ot=h("p"),ot.textContent=O,ft=r(),u(F.$$.fragment),tt=r(),lt=h("a"),v=r(),u(kt.$$.fragment),yt=r(),Z=h("p"),Z.textContent=Ut,z=r(),u(N.$$.fragment),et=r(),Y=h("a"),Tt=r(),u(C.$$.fragment),st=r(),u(_.$$.fragment),bt=r(),wt=h("a"),B=r(),u(E.$$.fragment),l=r(),d=h("p"),d.textContent=jt,Jt=r(),n=h("ul"),n.innerHTML=c,Rt=r(),u(vt.$$.fragment),Ct=r(),Wt=h("p"),this.h()},l(s){const o=oe("svelte-u9bgzb",document.head);i=M(o,"META",{name:!0,content:!0}),o.forEach(e),T=p(s),m=M(s,"P",{}),It(m).forEach(e),J=p(s),$(k.$$.fragment,s),nt=p(s),$(A.$$.fragment,s),rt=p(s),L=M(s,"P",{"data-svelte-h":!0}),j(L)!=="svelte-lewprv"&&(L.textContent=pt),R=p(s),Q=M(s,"UL",{"data-svelte-h":!0}),j(Q)!=="svelte-1wj4lyf"&&(Q.innerHTML=ct),W=p(s),U=M(s,"A",{id:!0}),It(U).forEach(e),ht=p(s),$(q.$$.fragment,s),Mt=p(s),$(X.$$.fragment,s),H=p(s),at=M(s,"P",{"data-svelte-h":!0}),j(at)!=="svelte-agqeit"&&(at.textContent=ut),S=p(s),$t=M(s,"P",{"data-svelte-h":!0}),j($t)!=="svelte-1w9wcpp"&&($t.innerHTML=P),gt=p(s),$(V.$$.fragment,s),I=p(s),it=M(s,"P",{"data-svelte-h":!0}),j(it)!=="svelte-grswur"&&(it.innerHTML=K),mt=p(s),$(x.$$.fragment,s),D=p(s),ot=M(s,"P",{"data-svelte-h":!0}),j(ot)!=="svelte-jaac36"&&(ot.textContent=O),ft=p(s),$(F.$$.fragment,s),tt=p(s),lt=M(s,"A",{id:!0}),It(lt).forEach(e),v=p(s),$(kt.$$.fragment,s),yt=p(s),Z=M(s,"P",{"data-svelte-h":!0}),j(Z)!=="svelte-12mtsa7"&&(Z.textContent=Ut),z=p(s),$(N.$$.fragment,s),et=p(s),Y=M(s,"A",{id:!0}),It(Y).forEach(e),Tt=p(s),$(C.$$.fragment,s),st=p(s),$(_.$$.fragment,s),bt=p(s),wt=M(s,"A",{id:!0}),It(wt).forEach(e),B=p(s),$(E.$$.fragment,s),l=p(s),d=M(s,"P",{"data-svelte-h":!0}),j(d)!=="svelte-1nv5qh9"&&(d.textContent=jt),Jt=p(s),n=M(s,"UL",{"data-svelte-h":!0}),j(n)!=="svelte-7q2z1g"&&(n.innerHTML=c),Rt=p(s),$(vt.$$.fragment,s),Ct=p(s),Wt=M(s,"P",{}),It(Wt).forEach(e),this.h()},h(){Ht(i,"name","hf:doc:metadata"),Ht(i,"content",Te),Ht(U,"id","data-processing"),Ht(lt,"id","trainer"),Ht(Y,"id","pytorch_native"),Ht(wt,"id","additional-resources")},m(s,o){Gt(document.head,i),a(s,T,o),a(s,m,o),a(s,J,o),g(k,s,o),a(s,nt,o),g(A,s,o),a(s,rt,o),a(s,L,o),a(s,R,o),a(s,Q,o),a(s,W,o),a(s,U,o),a(s,ht,o),g(q,s,o),a(s,Mt,o),g(X,s,o),a(s,H,o),a(s,at,o),a(s,S,o),a(s,$t,o),a(s,gt,o),g(V,s,o),a(s,I,o),a(s,it,o),a(s,mt,o),g(x,s,o),a(s,D,o),a(s,ot,o),a(s,ft,o),g(F,s,o),a(s,tt,o),a(s,lt,o),a(s,v,o),g(kt,s,o),a(s,yt,o),a(s,Z,o),a(s,z,o),g(N,s,o),a(s,et,o),a(s,Y,o),a(s,Tt,o),g(C,s,o),a(s,st,o),g(_,s,o),a(s,bt,o),a(s,wt,o),a(s,B,o),g(E,s,o),a(s,l,o),a(s,d,o),a(s,Jt,o),a(s,n,o),a(s,Rt,o),g(vt,s,o),a(s,Ct,o),a(s,Wt,o),_t=!0},p(s,[o]){const Nt={};o&2&&(Nt.$$scope={dirty:o,ctx:s}),N.$set(Nt);const Xt={};o&2&&(Xt.$$scope={dirty:o,ctx:s}),_.$set(Xt)},i(s){_t||(y(k.$$.fragment,s),y(A.$$.fragment,s),y(q.$$.fragment,s),y(X.$$.fragment,s),y(V.$$.fragment,s),y(x.$$.fragment,s),y(F.$$.fragment,s),y(kt.$$.fragment,s),y(N.$$.fragment,s),y(C.$$.fragment,s),y(_.$$.fragment,s),y(E.$$.fragment,s),y(vt.$$.fragment,s),_t=!0)},o(s){w(k.$$.fragment,s),w(A.$$.fragment,s),w(q.$$.fragment,s),w(X.$$.fragment,s),w(V.$$.fragment,s),w(x.$$.fragment,s),w(F.$$.fragment,s),w(kt.$$.fragment,s),w(N.$$.fragment,s),w(C.$$.fragment,s),w(_.$$.fragment,s),w(E.$$.fragment,s),w(vt.$$.fragment,s),_t=!1},d(s){s&&(e(T),e(m),e(J),e(nt),e(rt),e(L),e(R),e(Q),e(W),e(U),e(ht),e(Mt),e(H),e(at),e(S),e($t),e(gt),e(I),e(it),e(mt),e(D),e(ot),e(ft),e(tt),e(lt),e(v),e(yt),e(Z),e(z),e(et),e(Y),e(Tt),e(st),e(bt),e(wt),e(B),e(l),e(d),e(Jt),e(n),e(Rt),e(Ct),e(Wt)),e(i),b(k,s),b(A,s),b(q,s),b(X,s),b(V,s),b(x,s),b(F,s),b(kt,s),b(N,s),b(C,s),b(_,s),b(E,s),b(vt,s)}}}const Te='{"title":"사전 학습된 모델 미세 튜닝하기","local":"finetune-a-pretrained-model","sections":[{"title":"데이터셋 준비","local":"prepare-a-dataset","sections":[],"depth":2},{"title":"Train","local":"train","sections":[],"depth":2},{"title":"파이토치 Trainer로 훈련하기","local":"train-with-pytorch-trainer","sections":[{"title":"하이퍼파라미터 훈련","local":"training-hyperparameters","sections":[],"depth":3},{"title":"평가 하기","local":"evaluate","sections":[],"depth":3},{"title":"훈련 하기","local":"trainer","sections":[],"depth":3}],"depth":2},{"title":"Keras로 텐서플로우 모델 훈련하기","local":"train-a-tensorflow-model-with-keras","sections":[{"title":"Keras용 데이터 로드","local":"loading-data-for-keras","sections":[],"depth":3},{"title":"데이터를 tf.data.Dataset으로 로드하기","local":"loading-data-as-a-tfdatadataset","sections":[],"depth":3}],"depth":2},{"title":"기본 파이토치로 훈련하기","local":"train-in-native-pytorch","sections":[{"title":"DataLoader","local":"dataloader","sections":[],"depth":3},{"title":"옵티마이저 및 학습 속도 스케줄러","local":"optimizer-and-learning-rate-scheduler","sections":[],"depth":3},{"title":"훈련 루프","local":"training-loop","sections":[],"depth":3},{"title":"평가 하기","local":"evaluate","sections":[],"depth":3}],"depth":2},{"title":"추가 자료","local":"additional-resources","sections":[],"depth":2}],"depth":1}';function Je(dt){return pe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends ie{constructor(i){super(),me(this,i,Je,je,re,{})}}export{Re as component};
