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 w,k as Ht,y as Gt,a as l,v as g,d as y,t as b,w as j}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}),w(i)!=="svelte-133r2kc"&&(i.textContent=T)},m(m,J){l(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/pr_30530/ko/main_classes/trainer#transformers.Trainer">Trainer</a> 클래스를 제공하여 훈련 루프를 직접 작성하지 않고도 쉽게 훈련을 시작할 수 있습니다. <a href="/docs/transformers/pr_30530/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/pr_30530/ko/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> 클래스를 생성합니다.',X,H,lt='이 튜토리얼에서는 기본 훈련 <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/pr_30530/ko/main_classes/trainer#transformers.Trainer">Trainer</a>는 훈련 중에 모델 성능을 자동으로 평가하지 않습니다. 평가 지표를 계산하고 보고할 함수를 <a href="/docs/transformers/pr_30530/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 모델은 로짓으로 반환한다는 점을 기억하세요):",z,tt,at,v,kt="미세 튜닝 중에 평가 지표를 모니터링하려면 훈련 인수에 <code>eval_strategy</code> 파라미터를 지정하여 각 에폭이 끝날 때 평가 지표를 확인할 수 있습니다:",yt,Z,Ut,F,N,et,Y='모델, 훈련 인수, 훈련 및 테스트 데이터셋, 평가 함수가 포함된 <a href="/docs/transformers/pr_30530/ko/main_classes/trainer#transformers.Trainer">Trainer</a> 객체를 만듭니다:',Tt,C,st,_,jt='그리고 <a href="/docs/transformers/pr_30530/ko/main_classes/trainer#transformers.Trainer.train">train()</a>을 호출하여 모델을 미세 튜닝합니다:',bt,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}}),F=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=lt,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,z=r(),u(tt.$$.fragment),at=r(),v=h("p"),v.innerHTML=kt,yt=r(),u(Z.$$.fragment),Ut=r(),u(F.$$.fragment),N=r(),et=h("p"),et.innerHTML=Y,Tt=r(),u(C.$$.fragment),st=r(),_=h("p"),_.innerHTML=jt,bt=r(),u(B.$$.fragment)},l(a){$(i.$$.fragment,a),T=p(a),$(m.$$.fragment,a),J=p(a),k=M(a,"P",{"data-svelte-h":!0}),w(k)!=="svelte-1ykloxx"&&(k.innerHTML=nt),A=p(a),rt=M(a,"P",{"data-svelte-h":!0}),w(rt)!=="svelte-vv5j33"&&(rt.innerHTML=L),pt=p(a),$(R.$$.fragment,a),Q=p(a),$(ct.$$.fragment,a),W=p(a),$(U.$$.fragment,a),ht=p(a),q=M(a,"P",{"data-svelte-h":!0}),w(q)!=="svelte-1kmo3jh"&&(q.innerHTML=Mt),X=p(a),H=M(a,"P",{"data-svelte-h":!0}),w(H)!=="svelte-17gf6c"&&(H.innerHTML=lt),ut=p(a),S=M(a,"P",{"data-svelte-h":!0}),w(S)!=="svelte-3gh4w5"&&(S.textContent=$t),P=p(a),$(gt.$$.fragment,a),V=p(a),$(I.$$.fragment,a),it=p(a),K=M(a,"P",{"data-svelte-h":!0}),w(K)!=="svelte-10notbb"&&(K.innerHTML=mt),x=p(a),$(D.$$.fragment,a),ot=p(a),O=M(a,"P",{"data-svelte-h":!0}),w(O)!=="svelte-fpot8d"&&(O.innerHTML=ft),z=p(a),$(tt.$$.fragment,a),at=p(a),v=M(a,"P",{"data-svelte-h":!0}),w(v)!=="svelte-6bm7jk"&&(v.innerHTML=kt),yt=p(a),$(Z.$$.fragment,a),Ut=p(a),$(F.$$.fragment,a),N=p(a),et=M(a,"P",{"data-svelte-h":!0}),w(et)!=="svelte-reqj4z"&&(et.innerHTML=Y),Tt=p(a),$(C.$$.fragment,a),st=p(a),_=M(a,"P",{"data-svelte-h":!0}),w(_)!=="svelte-x3zbxm"&&(_.innerHTML=jt),bt=p(a),$(B.$$.fragment,a)},m(a,d){g(i,a,d),l(a,T,d),g(m,a,d),l(a,J,d),l(a,k,d),l(a,A,d),l(a,rt,d),l(a,pt,d),g(R,a,d),l(a,Q,d),g(ct,a,d),l(a,W,d),g(U,a,d),l(a,ht,d),l(a,q,d),l(a,X,d),l(a,H,d),l(a,ut,d),l(a,S,d),l(a,P,d),g(gt,a,d),l(a,V,d),g(I,a,d),l(a,it,d),l(a,K,d),l(a,x,d),g(D,a,d),l(a,ot,d),l(a,O,d),l(a,z,d),g(tt,a,d),l(a,at,d),l(a,v,d),l(a,yt,d),g(Z,a,d),l(a,Ut,d),g(F,a,d),l(a,N,d),l(a,et,d),l(a,Tt,d),g(C,a,d),l(a,st,d),l(a,_,d),l(a,bt,d),g(B,a,d),E=!0},p(a,d){const wt={};d&2&&(wt.$$scope={dirty:d,ctx:a}),ct.$set(wt)},i(a){E||(y(i.$$.fragment,a),y(m.$$.fragment,a),y(R.$$.fragment,a),y(ct.$$.fragment,a),y(U.$$.fragment,a),y(gt.$$.fragment,a),y(I.$$.fragment,a),y(D.$$.fragment,a),y(tt.$$.fragment,a),y(Z.$$.fragment,a),y(F.$$.fragment,a),y(C.$$.fragment,a),y(B.$$.fragment,a),E=!0)},o(a){b(i.$$.fragment,a),b(m.$$.fragment,a),b(R.$$.fragment,a),b(ct.$$.fragment,a),b(U.$$.fragment,a),b(gt.$$.fragment,a),b(I.$$.fragment,a),b(D.$$.fragment,a),b(tt.$$.fragment,a),b(Z.$$.fragment,a),b(F.$$.fragment,a),b(C.$$.fragment,a),b(B.$$.fragment,a),E=!1},d(a){a&&(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(z),e(at),e(v),e(yt),e(Ut),e(N),e(et),e(Tt),e(st),e(_),e(bt)),j(i,a),j(m,a),j(R,a),j(ct,a),j(U,a),j(gt,a),j(I,a),j(D,a),j(tt,a),j(Z,a),j(F,a),j(C,a),j(B,a)}}}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){b(i.$$.fragment,m),T=!1},d(m){j(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}),w(i)!=="svelte-z0fgk0"&&(i.innerHTML=T)},m(m,J){l(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,lt="다음으로 토크나이저를 로드하고 데이터를 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,z,tt=`학습 속도가 느려지는 것을 피하려면 데이터를 <code>tf.data.Dataset</code>으로 로드할 수 있습니다. 원한다면 직접
<code>tf.data</code> 파이프라인을 직접 작성할 수도 있지만, 이 작업을 간편하게 수행하는 수 있는 두 가지 방법이 있습니다:`,at,v,kt=`<li><a href="/docs/transformers/pr_30530/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/pr_30530/ko/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset">prepare_tf_dataset()</a>을 사용하려면 먼저 다음 코드 샘플과 같이 토크나이저 출력을 데이터 세트에 열로 추가해야 합니다:',F,N,et,Y,Tt=`허깅 페이스 데이터셋은 기본적으로 디스크에 저장되므로 메모리 사용량을 늘리지 않는다는 점을 기억하세요!
열이 추가되면 데이터셋에서 배치를 스트리밍하고 각 배치에 패딩을 추가할 수 있으므로 전체 데이터셋에 패딩을 추가하는 것보다 패딩 토큰의 수를 크게 줄일 수 있습니다.`,C,st,_,jt,bt=`위의 코드 샘플에서는 배치가 로드될 때 올바르게 패딩할 수 있도록 <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,a="<code>tf.data.Dataset</code>을 생성한 후에는 이전과 마찬가지로 모델을 컴파일하고 훈련(fit)할 수 있습니다:",d,wt,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}}),wt=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=lt,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(),z=h("p"),z.innerHTML=tt,at=r(),v=h("ul"),v.innerHTML=kt,yt=r(),Z=h("p"),Z.innerHTML=Ut,F=r(),u(N.$$.fragment),et=r(),Y=h("p"),Y.textContent=Tt,C=r(),u(st.$$.fragment),_=r(),jt=h("p"),jt.innerHTML=bt,B=r(),E=h("p"),E.innerHTML=a,d=r(),u(wt.$$.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}),w(A)!=="svelte-ze9716"&&(A.textContent=rt),L=p(n),$(pt.$$.fragment,n),R=p(n),Q=M(n,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-15pnkld"&&(Q.textContent=ct),W=p(n),U=M(n,"P",{"data-svelte-h":!0}),w(U)!=="svelte-1u2iume"&&(U.innerHTML=ht),q=p(n),$(Mt.$$.fragment,n),X=p(n),H=M(n,"P",{"data-svelte-h":!0}),w(H)!=="svelte-kduu5a"&&(H.textContent=lt),ut=p(n),$(S.$$.fragment,n),$t=p(n),P=M(n,"P",{"data-svelte-h":!0}),w(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}),w(x)!=="svelte-1ggdj2"&&(x.textContent=D),ot=p(n),$(O.$$.fragment,n),ft=p(n),z=M(n,"P",{"data-svelte-h":!0}),w(z)!=="svelte-5ru8h1"&&(z.innerHTML=tt),at=p(n),v=M(n,"UL",{"data-svelte-h":!0}),w(v)!=="svelte-en27my"&&(v.innerHTML=kt),yt=p(n),Z=M(n,"P",{"data-svelte-h":!0}),w(Z)!=="svelte-1yernu6"&&(Z.innerHTML=Ut),F=p(n),$(N.$$.fragment,n),et=p(n),Y=M(n,"P",{"data-svelte-h":!0}),w(Y)!=="svelte-10zjmdj"&&(Y.textContent=Tt),C=p(n),$(st.$$.fragment,n),_=p(n),jt=M(n,"P",{"data-svelte-h":!0}),w(jt)!=="svelte-1k6j3lz"&&(jt.innerHTML=bt),B=p(n),E=M(n,"P",{"data-svelte-h":!0}),w(E)!=="svelte-zwzwju"&&(E.innerHTML=a),d=p(n),$(wt.$$.fragment,n),this.h()},h(){Ht(i,"id","keras")},m(n,c){l(n,i,c),l(n,T,c),g(m,n,c),l(n,J,c),g(k,n,c),l(n,nt,c),l(n,A,c),l(n,L,c),g(pt,n,c),l(n,R,c),l(n,Q,c),l(n,W,c),l(n,U,c),l(n,q,c),g(Mt,n,c),l(n,X,c),l(n,H,c),l(n,ut,c),g(S,n,c),l(n,$t,c),l(n,P,c),l(n,V,c),g(I,n,c),l(n,it,c),g(K,n,c),l(n,mt,c),l(n,x,c),l(n,ot,c),g(O,n,c),l(n,ft,c),l(n,z,c),l(n,at,c),l(n,v,c),l(n,yt,c),l(n,Z,c),l(n,F,c),g(N,n,c),l(n,et,c),l(n,Y,c),l(n,C,c),g(st,n,c),l(n,_,c),l(n,jt,c),l(n,B,c),l(n,E,c),l(n,d,c),g(wt,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(wt.$$.fragment,n),Jt=!0)},o(n){b(m.$$.fragment,n),b(k.$$.fragment,n),b(pt.$$.fragment,n),b(Mt.$$.fragment,n),b(S.$$.fragment,n),b(I.$$.fragment,n),b(K.$$.fragment,n),b(O.$$.fragment,n),b(N.$$.fragment,n),b(st.$$.fragment,n),b(wt.$$.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(z),e(at),e(v),e(yt),e(Z),e(F),e(et),e(Y),e(C),e(_),e(jt),e(B),e(E),e(d)),j(m,n),j(k,n),j(pt,n),j(Mt,n),j(S,n),j(I,n),j(K,n),j(O,n),j(N,n),j(st,n),j(wt,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){b(i.$$.fragment,m),T=!1},d(m){j(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}),w(i)!=="svelte-1ctkiwu"&&(i.innerHTML=T)},m(m,J){l(m,i,J)},p:te,d(m){m&&e(i)}}}function be(dt){let i,T,m,J='<a href="/docs/transformers/pr_30530/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,lt,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,z,tt,at,v,kt="훈련 및 테스트 데이터셋에 대한 ‘DataLoader’를 생성하여 데이터 배치를 반복할 수 있습니다:",yt,Z,Ut,F,N="예측을 위한 레이블 개수를 사용하여 모델을 로드합니다:",et,Y,Tt,C,st,_,jt='옵티마이저와 학습 속도 스케줄러를 생성하여 모델을 미세 조정합니다. 파이토치에서 제공하는 <a href="https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html" rel="nofollow"><code>AdamW</code></a> 옵티마이저를 사용해 보겠습니다:',bt,B,E,a,d='<a href="/docs/transformers/pr_30530/ko/main_classes/trainer#transformers.Trainer">Trainer</a>에서 기본 학습 속도 스케줄러를 생성합니다:',wt,Jt,n,c,Rt="마지막으로, GPU에 액세스할 수 있는 경우 ‘device’를 지정하여 GPU를 사용하도록 합니다. 그렇지 않으면 CPU에서 훈련하며 몇 분이 아닌 몇 시간이 걸릴 수 있습니다.",vt,Ct,Wt,_t,s,o,Nt="이제 훈련할 준비가 되었습니다! 🥳",Xt,Vt,At,xt,le='훈련 진행 상황을 추적하려면 <a href="https://tqdm.github.io/" rel="nofollow">tqdm</a> 라이브러리를 사용하여 트레이닝 단계 수에 진행률 표시줄을 추가하세요:',Lt,zt,Qt,Ft,qt,Yt,ae='<a href="/docs/transformers/pr_30530/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"}}),zt=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}}),Ft=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(),lt=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),z=r(),u(tt.$$.fragment),at=r(),v=h("p"),v.textContent=kt,yt=r(),u(Z.$$.fragment),Ut=r(),F=h("p"),F.textContent=N,et=r(),u(Y.$$.fragment),Tt=r(),u(C.$$.fragment),st=r(),_=h("p"),_.innerHTML=jt,bt=r(),u(B.$$.fragment),E=r(),a=h("p"),a.innerHTML=d,wt=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=le,Lt=r(),u(zt.$$.fragment),Qt=r(),u(Ft.$$.fragment),qt=r(),Yt=h("p"),Yt.innerHTML=ae,St=r(),u(Bt.$$.fragment)},l(t){$(i.$$.fragment,t),T=p(t),m=M(t,"P",{"data-svelte-h":!0}),w(m)!=="svelte-1ss18y7"&&(m.innerHTML=J),k=p(t),nt=M(t,"P",{"data-svelte-h":!0}),w(nt)!=="svelte-192c5yp"&&(nt.textContent=A),rt=p(t),$(L.$$.fragment,t),pt=p(t),R=M(t,"P",{"data-svelte-h":!0}),w(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}),w(ht)!=="svelte-1y5q08j"&&(ht.innerHTML=q),Mt=p(Et),$(X.$$.fragment,Et),Et.forEach(e),H=p(f),lt=M(f,"LI",{});var Kt=It(lt);ut=M(Kt,"P",{"data-svelte-h":!0}),w(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}),w(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}),w(D)!=="svelte-hdideh"&&(D.textContent=ot),O=p(t),$(ft.$$.fragment,t),z=p(t),$(tt.$$.fragment,t),at=p(t),v=M(t,"P",{"data-svelte-h":!0}),w(v)!=="svelte-1ektf94"&&(v.textContent=kt),yt=p(t),$(Z.$$.fragment,t),Ut=p(t),F=M(t,"P",{"data-svelte-h":!0}),w(F)!=="svelte-sqozl7"&&(F.textContent=N),et=p(t),$(Y.$$.fragment,t),Tt=p(t),$(C.$$.fragment,t),st=p(t),_=M(t,"P",{"data-svelte-h":!0}),w(_)!=="svelte-15zsq6h"&&(_.innerHTML=jt),bt=p(t),$(B.$$.fragment,t),E=p(t),a=M(t,"P",{"data-svelte-h":!0}),w(a)!=="svelte-158lt0m"&&(a.innerHTML=d),wt=p(t),$(Jt.$$.fragment,t),n=p(t),c=M(t,"P",{"data-svelte-h":!0}),w(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}),w(o)!=="svelte-1yeeebv"&&(o.textContent=Nt),Xt=p(t),$(Vt.$$.fragment,t),At=p(t),xt=M(t,"P",{"data-svelte-h":!0}),w(xt)!=="svelte-1atq943"&&(xt.innerHTML=le),Lt=p(t),$(zt.$$.fragment,t),Qt=p(t),$(Ft.$$.fragment,t),qt=p(t),Yt=M(t,"P",{"data-svelte-h":!0}),w(Yt)!=="svelte-1qe48nn"&&(Yt.innerHTML=ae),St=p(t),$(Bt.$$.fragment,t)},m(t,f){g(i,t,f),l(t,T,f),l(t,m,f),l(t,k,f),l(t,nt,f),l(t,rt,f),g(L,t,f),l(t,pt,f),l(t,R,f),l(t,ct,f),l(t,W,f),Gt(W,U),Gt(U,ht),Gt(U,Mt),g(X,U,null),Gt(W,H),Gt(W,lt),Gt(lt,ut),Gt(lt,$t),g(P,lt,null),Gt(W,gt),Gt(W,V),Gt(V,I),Gt(V,K),g(mt,V,null),l(t,x,f),l(t,D,f),l(t,O,f),g(ft,t,f),l(t,z,f),g(tt,t,f),l(t,at,f),l(t,v,f),l(t,yt,f),g(Z,t,f),l(t,Ut,f),l(t,F,f),l(t,et,f),g(Y,t,f),l(t,Tt,f),g(C,t,f),l(t,st,f),l(t,_,f),l(t,bt,f),g(B,t,f),l(t,E,f),l(t,a,f),l(t,wt,f),g(Jt,t,f),l(t,n,f),l(t,c,f),l(t,vt,f),g(Ct,t,f),l(t,Wt,f),g(_t,t,f),l(t,s,f),l(t,o,f),l(t,Xt,f),g(Vt,t,f),l(t,At,f),l(t,xt,f),l(t,Lt,f),g(zt,t,f),l(t,Qt,f),g(Ft,t,f),l(t,qt,f),l(t,Yt,f),l(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(zt.$$.fragment,t),y(Ft.$$.fragment,t),y(Bt.$$.fragment,t),Pt=!0)},o(t){b(i.$$.fragment,t),b(L.$$.fragment,t),b(X.$$.fragment,t),b(P.$$.fragment,t),b(mt.$$.fragment,t),b(ft.$$.fragment,t),b(tt.$$.fragment,t),b(Z.$$.fragment,t),b(Y.$$.fragment,t),b(C.$$.fragment,t),b(B.$$.fragment,t),b(Jt.$$.fragment,t),b(Ct.$$.fragment,t),b(_t.$$.fragment,t),b(Vt.$$.fragment,t),b(zt.$$.fragment,t),b(Ft.$$.fragment,t),b(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(z),e(at),e(v),e(yt),e(Ut),e(F),e(et),e(Tt),e(st),e(_),e(bt),e(E),e(a),e(wt),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)),j(i,t),j(L,t),j(X),j(P),j(mt),j(ft,t),j(tt,t),j(Z,t),j(Y,t),j(C,t),j(B,t),j(Jt,t),j(Ct,t),j(_t,t),j(Vt,t),j(zt,t),j(Ft,t),j(Bt,t)}}}function je(dt){let i,T;return i=new se({props:{$$slots:{default:[be]},$$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){b(i.$$.fragment,m),T=!1},d(m){j(i,m)}}}function we(dt){let i,T,m,J,k,nt,A,rt,L,pt="사전 학습된 모델을 사용하면 상당한 이점이 있습니다. 계산 비용과 탄소발자국을 줄이고, 처음부터 모델을 학습시킬 필요 없이 최신 모델을 사용할 수 있습니다. 🤗 Transformers는 다양한 작업을 위해 사전 학습된 수천 개의 모델에 액세스할 수 있습니다. 사전 학습된 모델을 사용하는 경우, 자신의 작업과 관련된 데이터셋을 사용해 학습합니다. 이것은 미세 튜닝이라고 하는 매우 강력한 훈련 기법입니다. 이 튜토리얼에서는 당신이 선택한 딥러닝 프레임워크로 사전 학습된 모델을 미세 튜닝합니다:",R,Q,ct='<li>🤗 Transformers로 사전 학습된 모델 미세 튜닝하기 <a href="/docs/transformers/pr_30530/ko/main_classes/trainer#transformers.Trainer">Trainer</a>.</li> <li>Keras를 사용하여 TensorFlow에서 사전 학습된 모델을 미세 튜닝하기.</li> <li>기본 PyTorch에서 사전 학습된 모델을 미세 튜닝하기.</li>',W,U,ht,q,Mt,X,H,lt,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,z,tt,at,v,kt,yt,Z,Ut="여기서부터는 사용하려는 프레임워크에 해당하는 섹션을 따라야 합니다. 오른쪽 사이드바의 링크를 사용하여 원하는 프레임워크로 이동할 수 있으며, 특정 프레임워크의 모든 콘텐츠를 숨기려면 해당 프레임워크 블록의 오른쪽 상단에 있는 버튼을 사용하면 됩니다!",F,N,et,Y,Tt,C,st,_,jt,bt,B,E,a,d,wt="더 많은 미세 튜닝 예제는 다음을 참조하세요:",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}}),z=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:[je]},$$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(),lt=h("p"),lt.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(z.$$.fragment),tt=r(),at=h("a"),v=r(),u(kt.$$.fragment),yt=r(),Z=h("p"),Z.textContent=Ut,F=r(),u(N.$$.fragment),et=r(),Y=h("a"),Tt=r(),u(C.$$.fragment),st=r(),u(_.$$.fragment),jt=r(),bt=h("a"),B=r(),u(E.$$.fragment),a=r(),d=h("p"),d.textContent=wt,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}),w(L)!=="svelte-lewprv"&&(L.textContent=pt),R=p(s),Q=M(s,"UL",{"data-svelte-h":!0}),w(Q)!=="svelte-keoobm"&&(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),lt=M(s,"P",{"data-svelte-h":!0}),w(lt)!=="svelte-agqeit"&&(lt.textContent=ut),S=p(s),$t=M(s,"P",{"data-svelte-h":!0}),w($t)!=="svelte-1w9wcpp"&&($t.innerHTML=P),gt=p(s),$(V.$$.fragment,s),I=p(s),it=M(s,"P",{"data-svelte-h":!0}),w(it)!=="svelte-grswur"&&(it.innerHTML=K),mt=p(s),$(x.$$.fragment,s),D=p(s),ot=M(s,"P",{"data-svelte-h":!0}),w(ot)!=="svelte-jaac36"&&(ot.textContent=O),ft=p(s),$(z.$$.fragment,s),tt=p(s),at=M(s,"A",{id:!0}),It(at).forEach(e),v=p(s),$(kt.$$.fragment,s),yt=p(s),Z=M(s,"P",{"data-svelte-h":!0}),w(Z)!=="svelte-12mtsa7"&&(Z.textContent=Ut),F=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),jt=p(s),bt=M(s,"A",{id:!0}),It(bt).forEach(e),B=p(s),$(E.$$.fragment,s),a=p(s),d=M(s,"P",{"data-svelte-h":!0}),w(d)!=="svelte-1nv5qh9"&&(d.textContent=wt),Jt=p(s),n=M(s,"UL",{"data-svelte-h":!0}),w(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(at,"id","trainer"),Ht(Y,"id","pytorch_native"),Ht(bt,"id","additional-resources")},m(s,o){Gt(document.head,i),l(s,T,o),l(s,m,o),l(s,J,o),g(k,s,o),l(s,nt,o),g(A,s,o),l(s,rt,o),l(s,L,o),l(s,R,o),l(s,Q,o),l(s,W,o),l(s,U,o),l(s,ht,o),g(q,s,o),l(s,Mt,o),g(X,s,o),l(s,H,o),l(s,lt,o),l(s,S,o),l(s,$t,o),l(s,gt,o),g(V,s,o),l(s,I,o),l(s,it,o),l(s,mt,o),g(x,s,o),l(s,D,o),l(s,ot,o),l(s,ft,o),g(z,s,o),l(s,tt,o),l(s,at,o),l(s,v,o),g(kt,s,o),l(s,yt,o),l(s,Z,o),l(s,F,o),g(N,s,o),l(s,et,o),l(s,Y,o),l(s,Tt,o),g(C,s,o),l(s,st,o),g(_,s,o),l(s,jt,o),l(s,bt,o),l(s,B,o),g(E,s,o),l(s,a,o),l(s,d,o),l(s,Jt,o),l(s,n,o),l(s,Rt,o),g(vt,s,o),l(s,Ct,o),l(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(z.$$.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){b(k.$$.fragment,s),b(A.$$.fragment,s),b(q.$$.fragment,s),b(X.$$.fragment,s),b(V.$$.fragment,s),b(x.$$.fragment,s),b(z.$$.fragment,s),b(kt.$$.fragment,s),b(N.$$.fragment,s),b(C.$$.fragment,s),b(_.$$.fragment,s),b(E.$$.fragment,s),b(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(lt),e(S),e($t),e(gt),e(I),e(it),e(mt),e(D),e(ot),e(ft),e(tt),e(at),e(v),e(yt),e(Z),e(F),e(et),e(Y),e(Tt),e(st),e(jt),e(bt),e(B),e(a),e(d),e(Jt),e(n),e(Rt),e(Ct),e(Wt)),e(i),j(k,s),j(A,s),j(q,s),j(X,s),j(V,s),j(x,s),j(z,s),j(kt,s),j(N,s),j(C,s),j(_,s),j(E,s),j(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,we,re,{})}}export{Re as component};
