import{S as ms,i as us,s as ps,e as c,k as m,w as v,t as s,M as gs,c as l,d as h,m as u,x as y,a as i,h as a,b as d,G as n,g as r,y as $,q as b,o as k,B as E,v as fs}from"../../chunks/vendor-hf-doc-builder.js";import{T as ah}from"../../chunks/Tip-hf-doc-builder.js";import{Y as ch}from"../../chunks/Youtube-hf-doc-builder.js";import{I as lh}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as M}from"../../chunks/CodeBlock-hf-doc-builder.js";import{C as ds}from"../../chunks/CourseFloatingBanner-hf-doc-builder.js";import{F as _s}from"../../chunks/FrameworkSwitchCourse-hf-doc-builder.js";import"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function vs(F){let o,C,p,q,_;return{c(){o=c("p"),C=s("L\u01B0u \xFD r\u1EB1ng \u{1F917} c\xE1c m\xF4 h\xECnh Transformers c\xF3 m\u1ED9t kh\u1EA3 n\u0103ng \u0111\u1EB7c bi\u1EC7t m\xE0 h\u1EA7u h\u1EBFt c\xE1c m\xF4 h\xECnh Keras kh\xF4ng c\xF3 - ch\xFAng c\xF3 th\u1EC3 t\u1EF1 \u0111\u1ED9ng s\u1EED d\u1EE5ng m\u1ED9t l\u01B0\u1EE3ng m\u1EA5t m\xE1t th\xEDch h\u1EE3p m\xE0 ch\xFAng t\xEDnh to\xE1n b\xEAn trong. Ch\xFAng s\u1EBD s\u1EED d\u1EE5ng s\u1EF1 m\u1EA5t m\xE1t n\xE0y theo m\u1EB7c \u0111\u1ECBnh n\u1EBFu b\u1EA1n kh\xF4ng \u0111\u1EB7t tham s\u1ED1 m\u1EA5t m\xE1t b\xEAn trong "),p=c("code"),q=s("compile()"),_=s(". L\u01B0u \xFD r\u1EB1ng \u0111\u1EC3 s\u1EED d\u1EE5ng h\xE0m m\u1EA5t m\xE1t trong n\u1ED9i b\u1ED9, b\u1EA1n s\u1EBD c\u1EA7n truy\u1EC1n c\xE1c nh\xE3n c\u1EE7a m\xECnh nh\u01B0 m\u1ED9t ph\u1EA7n c\u1EE7a \u0111\u1EA7u v\xE0o, kh\xF4ng ph\u1EA3i d\u01B0\u1EDBi d\u1EA1ng nh\xE3n ri\xEAng bi\u1EC7t, \u0111\xE2y l\xE0 c\xE1ch th\xF4ng th\u01B0\u1EDDng \u0111\u1EC3 s\u1EED d\u1EE5ng nh\xE3n v\u1EDBi c\xE1c m\xF4 h\xECnh Keras. B\u1EA1n s\u1EBD th\u1EA5y c\xE1c v\xED d\u1EE5 v\u1EC1 \u0111i\u1EC1u n\xE0y trong Ph\u1EA7n 2 c\u1EE7a kh\xF3a h\u1ECDc, trong \u0111\xF3 vi\u1EC7c x\xE1c \u0111\u1ECBnh h\xE0m m\u1EA5t m\xE1t ch\xEDnh x\xE1c c\xF3 th\u1EC3 kh\xF3 kh\u0103n. Tuy nhi\xEAn, \u0111\u1ED1i v\u1EDBi ph\xE2n lo\u1EA1i chu\u1ED7i, m\u1ED9t h\xE0m m\u1EA5t m\xE1t Keras ti\xEAu chu\u1EA9n ho\u1EA1t \u0111\u1ED9ng kh\xE1 t\u1ED1t, v\xEC v\u1EADy \u0111\xF3 l\xE0 nh\u1EEFng g\xEC ch\xFAng ta s\u1EBD s\u1EED d\u1EE5ng \u1EDF \u0111\xE2y.")},l(g){o=l(g,"P",{});var w=i(o);C=a(w,"L\u01B0u \xFD r\u1EB1ng \u{1F917} c\xE1c m\xF4 h\xECnh Transformers c\xF3 m\u1ED9t kh\u1EA3 n\u0103ng \u0111\u1EB7c bi\u1EC7t m\xE0 h\u1EA7u h\u1EBFt c\xE1c m\xF4 h\xECnh Keras kh\xF4ng c\xF3 - ch\xFAng c\xF3 th\u1EC3 t\u1EF1 \u0111\u1ED9ng s\u1EED d\u1EE5ng m\u1ED9t l\u01B0\u1EE3ng m\u1EA5t m\xE1t th\xEDch h\u1EE3p m\xE0 ch\xFAng t\xEDnh to\xE1n b\xEAn trong. Ch\xFAng s\u1EBD s\u1EED d\u1EE5ng s\u1EF1 m\u1EA5t m\xE1t n\xE0y theo m\u1EB7c \u0111\u1ECBnh n\u1EBFu b\u1EA1n kh\xF4ng \u0111\u1EB7t tham s\u1ED1 m\u1EA5t m\xE1t b\xEAn trong "),p=l(w,"CODE",{});var j=i(p);q=a(j,"compile()"),j.forEach(h),_=a(w,". L\u01B0u \xFD r\u1EB1ng \u0111\u1EC3 s\u1EED d\u1EE5ng h\xE0m m\u1EA5t m\xE1t trong n\u1ED9i b\u1ED9, b\u1EA1n s\u1EBD c\u1EA7n truy\u1EC1n c\xE1c nh\xE3n c\u1EE7a m\xECnh nh\u01B0 m\u1ED9t ph\u1EA7n c\u1EE7a \u0111\u1EA7u v\xE0o, kh\xF4ng ph\u1EA3i d\u01B0\u1EDBi d\u1EA1ng nh\xE3n ri\xEAng bi\u1EC7t, \u0111\xE2y l\xE0 c\xE1ch th\xF4ng th\u01B0\u1EDDng \u0111\u1EC3 s\u1EED d\u1EE5ng nh\xE3n v\u1EDBi c\xE1c m\xF4 h\xECnh Keras. B\u1EA1n s\u1EBD th\u1EA5y c\xE1c v\xED d\u1EE5 v\u1EC1 \u0111i\u1EC1u n\xE0y trong Ph\u1EA7n 2 c\u1EE7a kh\xF3a h\u1ECDc, trong \u0111\xF3 vi\u1EC7c x\xE1c \u0111\u1ECBnh h\xE0m m\u1EA5t m\xE1t ch\xEDnh x\xE1c c\xF3 th\u1EC3 kh\xF3 kh\u0103n. Tuy nhi\xEAn, \u0111\u1ED1i v\u1EDBi ph\xE2n lo\u1EA1i chu\u1ED7i, m\u1ED9t h\xE0m m\u1EA5t m\xE1t Keras ti\xEAu chu\u1EA9n ho\u1EA1t \u0111\u1ED9ng kh\xE1 t\u1ED1t, v\xEC v\u1EADy \u0111\xF3 l\xE0 nh\u1EEFng g\xEC ch\xFAng ta s\u1EBD s\u1EED d\u1EE5ng \u1EDF \u0111\xE2y."),w.forEach(h)},m(g,w){r(g,o,w),n(o,C),n(o,p),n(p,q),n(o,_)},d(g){g&&h(o)}}}function ys(F){let o,C,p,q,_,g,w,j;return{c(){o=c("p"),C=s("L\u01B0u \xFD m\u1ED9t l\u1ED7i r\u1EA5t ph\u1ED5 bi\u1EBFn \u1EDF \u0111\xE2y - b\u1EA1n "),p=c("em"),q=s("c\xF3 th\u1EC3"),_=s(" ch\u1EC9 c\u1EA7n truy\u1EC1n t\xEAn c\u1EE7a h\xE0m m\u1EA5t m\xE1t d\u01B0\u1EDBi d\u1EA1ng chu\u1ED7i cho Keras, nh\u01B0ng theo m\u1EB7c \u0111\u1ECBnh, Keras s\u1EBD cho r\u1EB1ng b\u1EA1n \u0111\xE3 \xE1p d\u1EE5ng softmax cho \u0111\u1EA7u ra c\u1EE7a m\xECnh. Tuy nhi\xEAn, nhi\u1EC1u m\xF4 h\xECnh xu\u1EA5t ra c\xE1c gi\xE1 tr\u1ECB ngay tr\u01B0\u1EDBc khi \xE1p d\u1EE5ng softmax, c\xF2n \u0111\u01B0\u1EE3c g\u1ECDi l\xE0 "),g=c("em"),w=s("logit"),j=s(". Ch\xFAng ta c\u1EA7n n\xF3i v\u1EDBi h\xE0m m\u1EA5t m\xE1t r\u1EB1ng \u0111\xF3 l\xE0 nh\u1EEFng g\xEC m\xF4 h\xECnh c\u1EE7a ch\xFAng ta l\xE0m v\xE0 c\xE1ch duy nh\u1EA5t \u0111\u1EC3 l\xE0m \u0111i\u1EC1u \u0111\xF3 l\xE0 g\u1ECDi n\xF3 tr\u1EF1c ti\u1EBFp, thay v\xEC \u0111\u1EB7t t\xEAn b\u1EB1ng m\u1ED9t chu\u1ED7i.")},l(T){o=l(T,"P",{});var f=i(o);C=a(f,"L\u01B0u \xFD m\u1ED9t l\u1ED7i r\u1EA5t ph\u1ED5 bi\u1EBFn \u1EDF \u0111\xE2y - b\u1EA1n "),p=l(f,"EM",{});var A=i(p);q=a(A,"c\xF3 th\u1EC3"),A.forEach(h),_=a(f," ch\u1EC9 c\u1EA7n truy\u1EC1n t\xEAn c\u1EE7a h\xE0m m\u1EA5t m\xE1t d\u01B0\u1EDBi d\u1EA1ng chu\u1ED7i cho Keras, nh\u01B0ng theo m\u1EB7c \u0111\u1ECBnh, Keras s\u1EBD cho r\u1EB1ng b\u1EA1n \u0111\xE3 \xE1p d\u1EE5ng softmax cho \u0111\u1EA7u ra c\u1EE7a m\xECnh. Tuy nhi\xEAn, nhi\u1EC1u m\xF4 h\xECnh xu\u1EA5t ra c\xE1c gi\xE1 tr\u1ECB ngay tr\u01B0\u1EDBc khi \xE1p d\u1EE5ng softmax, c\xF2n \u0111\u01B0\u1EE3c g\u1ECDi l\xE0 "),g=l(f,"EM",{});var P=i(g);w=a(P,"logit"),P.forEach(h),j=a(f,". Ch\xFAng ta c\u1EA7n n\xF3i v\u1EDBi h\xE0m m\u1EA5t m\xE1t r\u1EB1ng \u0111\xF3 l\xE0 nh\u1EEFng g\xEC m\xF4 h\xECnh c\u1EE7a ch\xFAng ta l\xE0m v\xE0 c\xE1ch duy nh\u1EA5t \u0111\u1EC3 l\xE0m \u0111i\u1EC1u \u0111\xF3 l\xE0 g\u1ECDi n\xF3 tr\u1EF1c ti\u1EBFp, thay v\xEC \u0111\u1EB7t t\xEAn b\u1EB1ng m\u1ED9t chu\u1ED7i."),f.forEach(h)},m(T,f){r(T,o,f),n(o,C),n(o,p),n(p,q),n(o,_),n(o,g),n(g,w),n(o,j)},d(T){T&&h(o)}}}function $s(F){let o,C,p,q,_,g,w,j;return{c(){o=c("p"),C=s("Th\u01B0 vi\u1EC7n \u{1F917} Transformers c\u0169ng c\xF3 m\u1ED9t h\xE0m "),p=c("code"),q=s("create_optimizer()"),_=s(" s\u1EBD t\u1EA1o ra m\u1ED9t tr\xECnh t\u1ED1i \u01B0u h\xF3a "),g=c("code"),w=s("AdamW"),j=s(" v\u1EDBi s\u1EF1 gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc. \u0110\xE2y l\xE0 m\u1ED9t ph\xEDm t\u1EAFt thu\u1EADn ti\u1EC7n m\xE0 b\u1EA1n s\u1EBD th\u1EA5y chi ti\u1EBFt trong c\xE1c ph\u1EA7n sau c\u1EE7a kh\xF3a h\u1ECDc.")},l(T){o=l(T,"P",{});var f=i(o);C=a(f,"Th\u01B0 vi\u1EC7n \u{1F917} Transformers c\u0169ng c\xF3 m\u1ED9t h\xE0m "),p=l(f,"CODE",{});var A=i(p);q=a(A,"create_optimizer()"),A.forEach(h),_=a(f," s\u1EBD t\u1EA1o ra m\u1ED9t tr\xECnh t\u1ED1i \u01B0u h\xF3a "),g=l(f,"CODE",{});var P=i(g);w=a(P,"AdamW"),P.forEach(h),j=a(f," v\u1EDBi s\u1EF1 gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc. \u0110\xE2y l\xE0 m\u1ED9t ph\xEDm t\u1EAFt thu\u1EADn ti\u1EC7n m\xE0 b\u1EA1n s\u1EBD th\u1EA5y chi ti\u1EBFt trong c\xE1c ph\u1EA7n sau c\u1EE7a kh\xF3a h\u1ECDc."),f.forEach(h)},m(T,f){r(T,o,f),n(o,C),n(o,p),n(p,q),n(o,_),n(o,g),n(g,w),n(o,j)},d(T){T&&h(o)}}}function bs(F){let o,C,p,q,_,g,w,j,T,f;return{c(){o=c("p"),C=s("\u{1F4A1} N\u1EBFu b\u1EA1n mu\u1ED1n t\u1EF1 \u0111\u1ED9ng t\u1EA3i m\xF4 h\xECnh c\u1EE7a m\xECnh l\xEAn Hub trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n, b\u1EA1n c\xF3 th\u1EC3 truy\u1EC1n "),p=c("code"),q=s("PushToHubCallback"),_=s(" v\xE0o trong ph\u01B0\u01A1ng th\u1EE9c "),g=c("code"),w=s("model.fit()"),j=s(". Ch\xFAng ta s\u1EBD t\xECm hi\u1EC3u th\xEAm v\u1EC1 \u0111i\u1EC1u n\xE0y trong "),T=c("a"),f=s("Ch\u01B0\u01A1ng 4"),this.h()},l(A){o=l(A,"P",{});var P=i(o);C=a(P,"\u{1F4A1} N\u1EBFu b\u1EA1n mu\u1ED1n t\u1EF1 \u0111\u1ED9ng t\u1EA3i m\xF4 h\xECnh c\u1EE7a m\xECnh l\xEAn Hub trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n, b\u1EA1n c\xF3 th\u1EC3 truy\u1EC1n "),p=l(P,"CODE",{});var N=i(p);q=a(N,"PushToHubCallback"),N.forEach(h),_=a(P," v\xE0o trong ph\u01B0\u01A1ng th\u1EE9c "),g=l(P,"CODE",{});var at=i(g);w=a(at,"model.fit()"),at.forEach(h),j=a(P,". Ch\xFAng ta s\u1EBD t\xECm hi\u1EC3u th\xEAm v\u1EC1 \u0111i\u1EC1u n\xE0y trong "),T=l(P,"A",{href:!0});var S=i(T);f=a(S,"Ch\u01B0\u01A1ng 4"),S.forEach(h),P.forEach(h),this.h()},h(){d(T,"href","/course/chapter4/3")},m(A,P){r(A,o,P),n(o,C),n(o,p),n(p,q),n(o,_),n(o,g),n(g,w),n(o,j),n(o,T),n(T,f)},d(A){A&&h(o)}}}function ks(F){let o,C,p,q,_,g,w,j,T,f,A,P,N,at,S,ih,Ot,rh,oh,ct,mh,uh,fn,jt,ph,dn,lt,_n,U,W,Bt,it,gh,Gt,fh,vn,Tt,dh,yn,rt,$n,Pt,_h,bn,ot,kn,O,vh,xt,yh,$h,Lt,bh,kh,En,mt,wn,V,Eh,At,wh,Ch,Cn,B,qh,Ut,jh,Th,Ht,Ph,xh,qn,Y,jn,ut,Tn,J,Pn,H,Q,Rt,pt,Ah,It,zh,xn,gt,An,G,Sh,Wt,Dh,Kh,Vt,Fh,Mh,zn,x,Nh,Yt,Oh,Bh,Jt,Gh,Lh,Qt,Uh,Hh,Xt,Rh,Ih,Zt,Wh,Vh,tn,Yh,Jh,Sn,ft,Dn,X,Kn,zt,Qh,Fn,dt,Mn,St,Xh,Nn,_t,On,Z,Bn,R,tt,nn,vt,Zh,hn,te,Gn,yt,Ln,L,ne,en,he,ee,sn,se,ae,Un,$t,Hn,nt,ce,an,le,ie,Rn,bt,In,kt,Wn,D,re,cn,oe,me,ln,ue,pe,rn,ge,fe,Vn,Et,Yn,wt,Jn,K,de,Ct,_e,ve,on,ye,$e,mn,be,ke,Qn,ht,Ee,Dt,we,Ce,Xn;return p=new _s({props:{fw:F[0]}}),j=new lh({}),N=new ds({props:{chapter:3,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/vi/chapter3/section3_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/vi/chapter3/section3_tf.ipynb"}]}}),lt=new M({props:{code:`from datasets import load_dataset
from transformers import AutoTokenizer, DataCollatorWithPadding
import numpy as np

raw_datasets = load_dataset("glue", "mrpc")
checkpoint = "bert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)


def tokenize_function(example):
    return tokenizer(example["sentence1"], example["sentence2"], truncation=True)


tokenized_datasets = raw_datasets.map(tokenize_function, batched=True)

data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors="tf")

tf_train_dataset = tokenized_datasets["train"].to_tf_dataset(
    columns=["attention_mask", "input_ids", "token_type_ids"],
    label_cols=["labels"],
    shuffle=True,
    collate_fn=data_collator,
    batch_size=8,
)

tf_validation_dataset = tokenized_datasets["validation"].to_tf_dataset(
    columns=["attention_mask", "input_ids", "token_type_ids"],
    label_cols=["labels"],
    shuffle=False,
    collate_fn=data_collator,
    batch_size=8,
)`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, DataCollatorWithPadding
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

raw_datasets = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">example</span>):
    <span class="hljs-keyword">return</span> tokenizer(example[<span class="hljs-string">&quot;sentence1&quot;</span>], example[<span class="hljs-string">&quot;sentence2&quot;</span>], truncation=<span class="hljs-literal">True</span>)


tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)

data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)

tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)

tf_validation_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">False</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)`}}),it=new lh({}),rt=new ch({props:{id:"rnTGBy2ax1c"}}),ot=new ch({props:{id:"AUozVp78dhk"}}),mt=new M({props:{code:`from transformers import TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)`}}),Y=new ah({props:{$$slots:{default:[vs]},$$scope:{ctx:F}}}),ut=new M({props:{code:`from tensorflow.keras.losses import SparseCategoricalCrossentropy

model.compile(
    optimizer="adam",
    loss=SparseCategoricalCrossentropy(from_logits=True),
    metrics=["accuracy"],
)
model.fit(
    tf_train_dataset,
    validation_data=tf_validation_dataset,
)`,highlighted:`<span class="hljs-keyword">from</span> tensorflow.keras.losses <span class="hljs-keyword">import</span> SparseCategoricalCrossentropy

model.<span class="hljs-built_in">compile</span>(
    optimizer=<span class="hljs-string">&quot;adam&quot;</span>,
    loss=SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>),
    metrics=[<span class="hljs-string">&quot;accuracy&quot;</span>],
)
model.fit(
    tf_train_dataset,
    validation_data=tf_validation_dataset,
)`}}),J=new ah({props:{warning:!0,$$slots:{default:[ys]},$$scope:{ctx:F}}}),pt=new lh({}),gt=new ch({props:{id:"cpzq6ESSM5c"}}),ft=new M({props:{code:`from tensorflow.keras.optimizers.schedules import PolynomialDecay

batch_size = 8
num_epochs = 3
# S\u1ED1 b\u01B0\u1EDBc hu\u1EA5n luy\u1EC7n l\xE0 s\u1ED1 l\u01B0\u1EE3ng m\u1EABu trong t\u1EADp d\u1EEF li\u1EC7u, chia cho k\xEDch th\u01B0\u1EDBc l\xF4 sau \u0111\xF3 nh\xE2n
# v\u1EDBi t\u1ED5ng s\u1ED1 epoch. L\u01B0u \xFD r\u1EB1ng tf_train_dataset \u1EDF \u0111\xE2y l\xE0 tf.data.Dataset theo l\xF4,
# kh\xF4ng ph\u1EA3i l\xE0 Hugging Face Dataset, v\xEC v\u1EADy len() c\u1EE7a n\xF3 \u0111\xE3 l\xE0 num_samples // batch_size.
num_train_steps = len(tf_train_dataset) * num_epochs
lr_scheduler = PolynomialDecay(
    initial_learning_rate=5e-5, end_learning_rate=0.0, decay_steps=num_train_steps
)
from tensorflow.keras.optimizers import Adam

opt = Adam(learning_rate=lr_scheduler)`,highlighted:`<span class="hljs-keyword">from</span> tensorflow.keras.optimizers.schedules <span class="hljs-keyword">import</span> PolynomialDecay

batch_size = <span class="hljs-number">8</span>
num_epochs = <span class="hljs-number">3</span>
<span class="hljs-comment"># S\u1ED1 b\u01B0\u1EDBc hu\u1EA5n luy\u1EC7n l\xE0 s\u1ED1 l\u01B0\u1EE3ng m\u1EABu trong t\u1EADp d\u1EEF li\u1EC7u, chia cho k\xEDch th\u01B0\u1EDBc l\xF4 sau \u0111\xF3 nh\xE2n</span>
<span class="hljs-comment"># v\u1EDBi t\u1ED5ng s\u1ED1 epoch. L\u01B0u \xFD r\u1EB1ng tf_train_dataset \u1EDF \u0111\xE2y l\xE0 tf.data.Dataset theo l\xF4,</span>
<span class="hljs-comment"># kh\xF4ng ph\u1EA3i l\xE0 Hugging Face Dataset, v\xEC v\u1EADy len() c\u1EE7a n\xF3 \u0111\xE3 l\xE0 num_samples // batch_size.</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_epochs
lr_scheduler = PolynomialDecay(
    initial_learning_rate=<span class="hljs-number">5e-5</span>, end_learning_rate=<span class="hljs-number">0.0</span>, decay_steps=num_train_steps
)
<span class="hljs-keyword">from</span> tensorflow.keras.optimizers <span class="hljs-keyword">import</span> Adam

opt = Adam(learning_rate=lr_scheduler)`}}),X=new ah({props:{$$slots:{default:[$s]},$$scope:{ctx:F}}}),dt=new M({props:{code:`import tensorflow as tf

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer=opt, loss=loss, metrics=["accuracy"])`,highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>)
model.<span class="hljs-built_in">compile</span>(optimizer=opt, loss=loss, metrics=[<span class="hljs-string">&quot;accuracy&quot;</span>])`}}),_t=new M({props:{code:"model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=3)",highlighted:'model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=<span class="hljs-number">3</span>)'}}),Z=new ah({props:{$$slots:{default:[bs]},$$scope:{ctx:F}}}),vt=new lh({}),yt=new ch({props:{id:"nx10eh4CoOs"}}),$t=new M({props:{code:'preds = model.predict(tf_validation_dataset)["logits"]',highlighted:'preds = model.predict(tf_validation_dataset)[<span class="hljs-string">&quot;logits&quot;</span>]'}}),bt=new M({props:{code:`class_preds = np.argmax(preds, axis=1)
print(preds.shape, class_preds.shape)`,highlighted:`class_preds = np.argmax(preds, axis=<span class="hljs-number">1</span>)
<span class="hljs-built_in">print</span>(preds.shape, class_preds.shape)`}}),kt=new M({props:{code:"(408, 2) (408,)",highlighted:'(<span class="hljs-number">408</span>, <span class="hljs-number">2</span>) (<span class="hljs-number">408</span>,)'}}),Et=new M({props:{code:`import evaluate

metric = evaluate.load("glue", "mrpc")
metric.compute(predictions=class_preds, references=raw_datasets["validation"]["label"])`,highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
metric.compute(predictions=class_preds, references=raw_datasets[<span class="hljs-string">&quot;validation&quot;</span>][<span class="hljs-string">&quot;label&quot;</span>])`}}),wt=new M({props:{code:"{'accuracy': 0.8578431372549019, 'f1': 0.8996539792387542}",highlighted:'{<span class="hljs-string">&#x27;accuracy&#x27;</span>: <span class="hljs-number">0.8578431372549019</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.8996539792387542</span>}'}}),{c(){o=c("meta"),C=m(),v(p.$$.fragment),q=m(),_=c("h1"),g=c("a"),w=c("span"),v(j.$$.fragment),T=m(),f=c("span"),A=s("Tinh ch\u1EC9nh m\u1ED9t m\xF4 h\xECnh v\u1EDBi Keras"),P=m(),v(N.$$.fragment),at=m(),S=c("p"),ih=s("Khi b\u1EA1n \u0111\xE3 ho\xE0n th\xE0nh t\u1EA5t c\u1EA3 c\xF4ng vi\u1EC7c ti\u1EC1n x\u1EED l\xFD d\u1EEF li\u1EC7u trong ph\u1EA7n tr\u01B0\u1EDBc, b\u1EA1n ch\u1EC9 c\xF2n m\u1ED9t v\xE0i b\u01B0\u1EDBc n\u1EEFa \u0111\u1EC3 hu\u1EA5n luy\u1EC7n m\xF4 h\xECnh. Tuy nhi\xEAn, l\u01B0u \xFD r\u1EB1ng l\u1EC7nh "),Ot=c("code"),rh=s("model.fit()"),oh=s(" s\u1EBD ch\u1EA1y r\u1EA5t ch\u1EADm tr\xEAn CPU. N\u1EBFu b\u1EA1n ch\u01B0a thi\u1EBFt l\u1EADp GPU, b\u1EA1n c\xF3 th\u1EC3 c\xF3 quy\u1EC1n truy c\u1EADp v\xE0o GPU ho\u1EB7c TPU mi\u1EC5n ph\xED tr\xEAn "),ct=c("a"),mh=s("Google Colab"),uh=s("."),fn=m(),jt=c("p"),ph=s("C\xE1c \u0111o\u1EA1n m\xE3 v\xED d\u1EE5 b\xEAn d\u01B0\u1EDBi gi\u1EA3 s\u1EED b\u1EA1n \u0111\xE3 th\u1EF1c thi c\xE1c v\xED d\u1EE5 trong ph\u1EA7n tr\u01B0\u1EDBc. D\u01B0\u1EDBi \u0111\xE2y l\xE0 m\u1ED9t b\u1EA3n t\xF3m t\u1EAFt ng\u1EAFn g\u1ECDn t\xF3m t\u1EAFt l\u1EA1i nh\u1EEFng g\xEC b\u1EA1n c\u1EA7n:"),dn=m(),v(lt.$$.fragment),_n=m(),U=c("h3"),W=c("a"),Bt=c("span"),v(it.$$.fragment),gh=m(),Gt=c("span"),fh=s("Hu\u1EA5n luy\u1EC7n"),vn=m(),Tt=c("p"),dh=s("C\xE1c m\xF4 h\xECnh TensorFlow nh\u1EADp t\u1EEB \u{1F917} Transformers v\u1ED1n l\xE0 c\xE1c m\xF4 h\xECnh Keras. \u0110\xE2y l\xE0 ph\u1EA7n gi\u1EDBi thi\u1EC7u ng\u1EAFn v\u1EC1 Keras."),yn=m(),v(rt.$$.fragment),$n=m(),Pt=c("p"),_h=s("\u0110i\u1EC1u \u0111\xF3 c\xF3 ngh\u0129a l\xE0 m\u1ED9t khi ch\xFAng t\xF4i c\xF3 d\u1EEF li\u1EC7u ri\xEAng m\xECnh, ch\xFAng ta ch\u1EC9 c\u1EA7n thao t\xE1c \xEDt b\u01B0\u1EDBc n\u1EEFa th\xF4i \u0111\u1EC3 b\u1EAFt \u0111\u1EA7u hu\u1EA5n luy\u1EC7n."),bn=m(),v(ot.$$.fragment),kn=m(),O=c("p"),vh=s("Nh\u01B0 trong "),xt=c("a"),yh=s("ch\u01B0\u01A1ng tr\u01B0\u1EDBc"),$h=s(", ch\xFAng ta s\u1EBD s\u1EED d\u1EE5ng l\u1EDBp "),Lt=c("code"),bh=s("TFAutoModelForSequenceClassification"),kh=s(", v\u1EDBi hai nh\xE3n:"),En=m(),v(mt.$$.fragment),wn=m(),V=c("p"),Eh=s("B\u1EA1n s\u1EBD nh\u1EADn th\u1EA5y r\u1EB1ng kh\xF4ng nh\u01B0 trong "),At=c("a"),wh=s("Ch\u01B0\u01A1ng 2"),Ch=s(", b\u1EA1n nh\u1EADn \u0111\u01B0\u1EE3c m\u1ED9t c\u1EA3nh b\xE1o sau khi kh\u1EDFi t\u1EA1o m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc n\xE0y. \u0110\xE2y l\xE0 do BERT ch\u01B0a \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc v\u1EC1 ph\xE2n lo\u1EA1i c\xE1c c\u1EB7p c\xE2u, v\xEC v\u1EADy ph\u1EA7n \u0111\u1EA7u c\u1EE7a m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc \u0111\xE3 b\u1ECB lo\u1EA1i b\u1ECF v\xE0 ph\u1EA7n \u0111\u1EA7u m\u1EDBi ph\xF9 h\u1EE3p \u0111\u1EC3 ph\xE2n lo\u1EA1i chu\u1ED7i \u0111\xE3 \u0111\u01B0\u1EE3c ch\xE8n v\xE0o thay th\u1EBF. C\xE1c c\u1EA3nh b\xE1o ch\u1EC9 ra r\u1EB1ng m\u1ED9t s\u1ED1 tr\u1ECDng s\u1ED1 \u0111\xE3 kh\xF4ng \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng (nh\u1EEFng tr\u1ECDng s\u1ED1 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi \u0111\u1EA7u hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc b\u1ECB r\u1EE5ng) v\xE0 m\u1ED9t s\u1ED1 tr\u1ECDng s\u1ED1 kh\xE1c kh\xE1c \u0111\u01B0\u1EE3c kh\u1EDFi t\u1EA1o ng\u1EABu nhi\xEAn (nh\u1EEFng tr\u1ECDng s\u1ED1 d\xE0nh cho \u0111\u1EA7u m\u1EDBi). N\xF3 k\u1EBFt th\xFAc b\u1EB1ng c\xE1ch khuy\u1EBFn kh\xEDch b\u1EA1n hu\u1EA5n luy\u1EC7n m\xF4 h\xECnh, \u0111\xF3 ch\xEDnh x\xE1c l\xE0 nh\u1EEFng g\xEC ch\xFAng ta s\u1EBD l\xE0m b\xE2y gi\u1EDD."),Cn=m(),B=c("p"),qh=s("\u0110\u1EC3 tinh ch\u1EC9nh m\xF4 h\xECnh tr\xEAn t\u1EADp d\u1EEF li\u1EC7u c\u1EE7a m\xECnh, ch\xFAng ta ch\u1EC9 c\u1EA7n "),Ut=c("code"),jh=s("compile()"),Th=s(" m\xF4 h\xECnh v\xE0 sau \u0111\xF3 chuy\u1EC3n d\u1EEF li\u1EC7u c\u1EE7a ta \u0111\u1EBFn ph\u01B0\u01A1ng th\u1EE9c "),Ht=c("code"),Ph=s("fit()"),xh=s(". Thao t\xE1c n\xE0y s\u1EBD b\u1EAFt \u0111\u1EA7u qu\xE1 tr\xECnh tinh ch\u1EC9nh (s\u1EBD m\u1EA5t v\xE0i ph\xFAt tr\xEAn GPU) v\xE0 b\xE1o c\xE1o s\u1EF1 m\u1EA5t m\xE1t \u1EDF t\u1EADp hu\u1EA5n luy\u1EC7n khi n\xF3 di\u1EC5n ra, c\u1ED9ng v\u1EDBi m\u1EA5t m\xE1t \u1EDF t\u1EADp ki\u1EC3m \u0111\u1ECBnh \u1EDF cu\u1ED1i m\u1ED7i epoch."),qn=m(),v(Y.$$.fragment),jn=m(),v(ut.$$.fragment),Tn=m(),v(J.$$.fragment),Pn=m(),H=c("h3"),Q=c("a"),Rt=c("span"),v(pt.$$.fragment),Ah=m(),It=c("span"),zh=s("C\u1EA3i thi\u1EC7n hi\u1EC7u su\u1EA5t hu\u1EA5n luy\u1EC7n"),xn=m(),v(gt.$$.fragment),An=m(),G=c("p"),Sh=s("N\u1EBFu b\u1EA1n th\u1EED \u0111o\u1EA1n m\xE3 tr\xEAn, n\xF3 ch\u1EAFc ch\u1EAFn ch\u1EA1y, nh\u01B0ng b\u1EA1n s\u1EBD th\u1EA5y r\u1EB1ng h\xE0m m\u1EA5t m\xE1t ch\u1EC9 gi\u1EA3m t\u1EEB t\u1EEB ho\u1EB7c kh\xF4ng th\u01B0\u1EDDng xuy\xEAn. Nguy\xEAn nh\xE2n ch\xEDnh l\xE0 do "),Wt=c("em"),Dh=s("learning rate"),Kh=s(" hay "),Vt=c("em"),Fh=s("t\u1ED1c \u0111\u1ED9 h\u1ECDc"),Mh=s(`. V\u1EDBi h\xE0m m\u1EA5t m\xE1t, khi ta truy\u1EC1n cho Keras t\xEAn c\u1EE7a tr\xECnh t\u1ED1i \u01B0u h\xF3a d\u01B0\u1EDBi d\u1EA1ng m\u1ED9t chu\u1ED7i, Keras s\u1EBD kh\u1EDFi t\u1EA1o tr\xECnh t\u1ED1i \u01B0u h\xF3a \u0111\xF3 v\u1EDBi c\xE1c gi\xE1 tr\u1ECB m\u1EB7c \u0111\u1ECBnh cho t\u1EA5t c\u1EA3 c\xE1c tham s\u1ED1, bao g\u1ED3m c\u1EA3 t\u1ED1c \u0111\u1ED9 h\u1ECDc. Tuy nhi\xEAn, t\u1EEB kinh nghi\u1EC7m l\xE2u n\u0103m, ch\xFAng t\xF4i bi\u1EBFt
r\u1EB1ng c\xE1c m\xF4 h\xECnh Transformer \u0111\u01B0\u1EE3c h\u01B0\u1EDFng l\u1EE3i t\u1EEB t\u1ED1c \u0111\u1ED9 h\u1ECDc th\u1EA5p h\u01A1n nhi\u1EC1u so v\u1EDBi t\u1EF7 l\u1EC7 m\u1EB7c \u0111\u1ECBnh cho Adam, l\xE0 1e-3, c\u0169ng \u0111\u01B0\u1EE3c vi\u1EBFt b\u1EB1ng 10 l\u0169y th\u1EEBa c\u1EE7a -3, ho\u1EB7c 0,001. 5e-5 (0,00005), th\u1EA5p h\u01A1n kho\u1EA3ng hai m\u01B0\u01A1i l\u1EA7n, l\xE0 m\u1ED9t \u0111i\u1EC3m kh\u1EDFi \u0111\u1EA7u t\u1ED1t h\u01A1n nhi\u1EC1u.`),zn=m(),x=c("p"),Nh=s("Ngo\xE0i vi\u1EC7c gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc, ch\xFAng t\xF4i c\xF3 m\u1ED9t m\u1EB9o th\u1EE9 hai: Ta c\xF3 th\u1EC3 t\u1EEB t\u1EEB gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n. Trong t\xE0i li\u1EC7u, \u0111\xF4i khi b\u1EA1n s\u1EBD th\u1EA5y \u0111i\u1EC1u n\xE0y \u0111\u01B0\u1EE3c g\u1ECDi l\xE0 "),Yt=c("em"),Oh=s("ph\xE2n r\xE3"),Bh=s(" ho\u1EB7c "),Jt=c("em"),Gh=s("\u1EE7"),Lh=s(" t\u1ED1c \u0111\u1ED9 h\u1ECDc. \u1EDE Keras, c\xE1ch t\u1ED1t nh\u1EA5t \u0111\u1EC3 l\xE0m \u0111i\u1EC1u n\xE0y l\xE0 s\u1EED d\u1EE5ng "),Qt=c("em"),Uh=s("learning rate scheduler"),Hh=s(" hay "),Xt=c("em"),Rh=s("c\xF4ng c\u1EE5 l\u1EADp l\u1ECBch tr\xECnh t\u1ED1c \u0111\u1ED9 h\u1ECDc"),Ih=s(". M\u1ED9t c\xE1i hay \u0111\u1EC3 s\u1EED d\u1EE5ng l\xE0 "),Zt=c("code"),Wh=s("PolynomialDecay"),Vh=s(" - v\u1EDBi c\xE0i \u0111\u1EB7t m\u1EB7c \u0111\u1ECBnh, n\xF3 ch\u1EC9 \u0111\u01A1n gi\u1EA3n l\xE0 gi\u1EA3m \u0111\u1ED9 tuy\u1EBFn t\xEDnh t\u1ED1c \u0111\u1ED9 h\u1ECDc t\u1EEB gi\xE1 tr\u1ECB ban \u0111\u1EA7u \u0111\u1EBFn gi\xE1 tr\u1ECB cu\u1ED1i c\xF9ng trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n, \u0111\xF3 ch\xEDnh x\xE1c l\xE0 nh\u1EEFng g\xEC ta mu\u1ED1n. Tuy nhi\xEAn, \u0111\u1EC3 s\u1EED d\u1EE5ng b\u1ED9 l\u1EADp l\u1ECBch m\u1ED9t c\xE1ch ch\xEDnh x\xE1c, ch\xFAng ta c\u1EA7n cho n\xF3 bi\u1EBFt th\u1EDDi gian hu\u1EA5n luy\u1EC7n s\u1EBD k\xE9o d\xE0i. Ch\xFAng ta t\xEDnh gi\xE1 tr\u1ECB \u0111\xF3 d\u01B0\u1EDBi d\u1EA1ng "),tn=c("code"),Yh=s("num_train_steps"),Jh=s(" nh\u01B0 sau."),Sn=m(),v(ft.$$.fragment),Dn=m(),v(X.$$.fragment),Kn=m(),zt=c("p"),Qh=s("B\xE2y gi\u1EDD ch\xFAng ta \u0111\xE3 c\xF3 tr\xECnh t\u1ED1i \u01B0u h\xF3a ho\xE0n to\xE0n m\u1EDBi v\xE0 ta c\xF3 th\u1EC3 th\u1EED hu\u1EA5n luy\u1EC7n v\u1EDBi n\xF3. \u0110\u1EA7u ti\xEAn, h\xE3y t\u1EA3i l\u1EA1i m\xF4 h\xECnh, \u0111\u1EC3 \u0111\u1EB7t l\u1EA1i c\xE1c thay \u0111\u1ED5i \u0111\u1ED1i v\u1EDBi tr\u1ECDng s\u1ED1 t\u1EEB l\u1EA7n ch\u1EA1y hu\u1EA5n luy\u1EC7n m\xE0 ch\xFAng ta v\u1EEBa th\u1EF1c hi\u1EC7n v\xE0 sau \u0111\xF3 ta c\xF3 th\u1EC3 bi\xEAn d\u1ECBch n\xF3 b\u1EB1ng tr\xECnh t\u1ED1i \u01B0u h\xF3a m\u1EDBi:"),Fn=m(),v(dt.$$.fragment),Mn=m(),St=c("p"),Xh=s("Gi\u1EDD ta s\u1EBD fit l\u1EA1i 1 l\u1EA7n n\u1EEFa:"),Nn=m(),v(_t.$$.fragment),On=m(),v(Z.$$.fragment),Bn=m(),R=c("h3"),tt=c("a"),nn=c("span"),v(vt.$$.fragment),Zh=m(),hn=c("span"),te=s("C\xE1c d\u1EF1 \u0111o\xE1n c\u1EE7a m\xF4 h\xECnh"),Gn=m(),v(yt.$$.fragment),Ln=m(),L=c("p"),ne=s("Vi\u1EC7c hu\u1EA5n luy\u1EC7n v\xE0 theo d\xF5i s\u1EF1 m\u1EA5t m\xE1t gi\u1EA3m xu\u1ED1ng \u0111\u1EC1u r\u1EA5t t\u1ED1t, nh\u01B0ng n\u1EBFu ch\xFAng ta mu\u1ED1n th\u1EF1c s\u1EF1 c\xF3 \u0111\u01B0\u1EE3c k\u1EBFt qu\u1EA3 \u0111\u1EA7u ra t\u1EEB m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n, \u0111\u1EC3 t\xEDnh to\xE1n m\u1ED9t s\u1ED1 ch\u1EC9 s\u1ED1 ho\u1EB7c s\u1EED d\u1EE5ng m\xF4 h\xECnh \u0111\xF3 trong s\u1EA3n xu\u1EA5t th\xEC sao? \u0110\u1EC3 l\xE0m \u0111i\u1EC1u \u0111\xF3, ch\xFAng ta ch\u1EC9 c\xF3 th\u1EC3 s\u1EED d\u1EE5ng ph\u01B0\u01A1ng th\u1EE9c "),en=c("code"),he=s("predict()"),ee=s(". \u0110i\u1EC1u n\xE0y s\u1EBD tr\u1EA3 v\u1EC1 "),sn=c("em"),se=s("logit"),ae=s(" t\u1EEB \u0111\u1EA7u ra c\u1EE7a m\xF4 h\xECnh, m\u1ED9t cho m\u1ED7i l\u1EDBp."),Un=m(),v($t.$$.fragment),Hn=m(),nt=c("p"),ce=s("Ch\xFAng ta c\xF3 th\u1EC3 chuy\u1EC3n \u0111\u1ED5i c\xE1c logit n\xE0y th\xE0nh c\xE1c d\u1EF1 \u0111o\xE1n l\u1EDBp c\u1EE7a m\xF4 h\xECnh b\u1EB1ng c\xE1ch s\u1EED d\u1EE5ng "),an=c("code"),le=s("argmax"),ie=s(" \u0111\u1EC3 t\xECm logit cao nh\u1EA5t, t\u01B0\u01A1ng \u1EE9ng v\u1EDBi l\u1EDBp c\xF3 nhi\u1EC1u kh\u1EA3 n\u0103ng nh\u1EA5t:"),Rn=m(),v(bt.$$.fragment),In=m(),v(kt.$$.fragment),Wn=m(),D=c("p"),re=s("B\xE2y gi\u1EDD, h\xE3y s\u1EED d\u1EE5ng c\xE1c "),cn=c("code"),oe=s("preds"),me=s(" \u0111\xF3 \u0111\u1EC3 t\xEDnh to\xE1n m\u1ED9t s\u1ED1 ch\u1EC9 s\u1ED1! Ch\xFAng ta c\xF3 th\u1EC3 t\u1EA3i c\xE1c ch\u1EC9 s\u1ED1 \u0111\u01B0\u1EE3c li\xEAn k\u1EBFt v\u1EDBi t\u1EADp d\u1EEF li\u1EC7u MRPC d\u1EC5 d\xE0ng nh\u01B0 khi ta t\u1EA3i t\u1EADp d\u1EEF li\u1EC7u, l\u1EA7n n\xE0y l\xE0 v\u1EDBi h\xE0m "),ln=c("code"),ue=s("eval.load())"),pe=s(". \u0110\u1ED1i t\u01B0\u1EE3ng \u0111\u01B0\u1EE3c tr\u1EA3 v\u1EC1 c\xF3 ph\u01B0\u01A1ng th\u1EE9c "),rn=c("code"),ge=s("compute()"),fe=s(" m\xE0 ch\xFAng ta c\xF3 th\u1EC3 s\u1EED d\u1EE5ng \u0111\u1EC3 th\u1EF1c hi\u1EC7n ph\xE9p t\xEDnh s\u1ED1 li\u1EC7u:"),Vn=m(),v(Et.$$.fragment),Yn=m(),v(wt.$$.fragment),Jn=m(),K=c("p"),de=s("K\u1EBFt qu\u1EA3 ch\xEDnh x\xE1c b\u1EA1n nh\u1EADn \u0111\u01B0\u1EE3c c\xF3 th\u1EC3 kh\xE1c nhau, v\xEC vi\u1EC7c kh\u1EDFi t\u1EA1o ng\u1EABu nhi\xEAn ph\u1EA7n \u0111\u1EA7u m\xF4 h\xECnh c\xF3 th\u1EC3 thay \u0111\u1ED5i c\xE1c ch\u1EC9 s\u1ED1 m\xE0 n\xF3 \u0111\u1EA1t \u0111\u01B0\u1EE3c. \u1EDE \u0111\xE2y, ch\xFAng ta c\xF3 th\u1EC3 th\u1EA5y m\xF4 h\xECnh c\xF3 \u0111\u1ED9 ch\xEDnh x\xE1c 85.78% tr\xEAn t\u1EADp ki\u1EC3m \u0111\u1ECBnh v\xE0 \u0111i\u1EC3m F1 l\xE0 89.97. \u0110\xF3 l\xE0 hai ch\u1EC9 s\u1ED1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng \u0111\u1EC3 \u0111\xE1nh gi\xE1 k\u1EBFt qu\u1EA3 tr\xEAn t\u1EADp d\u1EEF li\u1EC7u MRPC theo \u0111i\u1EC3m chu\u1EA9n GLUE. B\u1EA3ng trong "),Ct=c("a"),_e=s("b\xE0i b\xE1o BERT"),ve=s(" b\xE1o c\xE1o \u0111i\u1EC3m F1 l\xE0 88.9 cho m\xF4 h\xECnh c\u01A1 s\u1EDF. \u0110\xF3 l\xE0 m\xF4 h\xECnh "),on=c("code"),ye=s("kh\xF4ng ph\xE2n bi\u1EC7t"),$e=s(" vi\u1EBFt hoa vi\u1EBFt th\u01B0\u1EDDng trong khi ch\xFAng ta hi\u1EC7n \u0111ang s\u1EED d\u1EE5ng m\xF4 h\xECnh "),mn=c("code"),be=s("c\xF3 ph\xE2n bi\u1EC7t"),ke=s(", \u0111i\u1EC1u n\xE0y gi\u1EA3i th\xEDch k\u1EBFt qu\u1EA3 t\u1ED1t h\u01A1n."),Qn=m(),ht=c("p"),Ee=s("Ph\u1EA7n n\xE0y k\u1EBFt th\xFAc ph\u1EA7n gi\u1EDBi thi\u1EC7u v\u1EC1 c\xE1ch tinh ch\u1EC9nh b\u1EB1ng Keras API. M\u1ED9t v\xED d\u1EE5 v\u1EC1 c\xE1ch l\xE0m n\xE0y \u0111\u1ED1i v\u1EDBi h\u1EA7u h\u1EBFt c\xE1c t\xE1c v\u1EE5 NLP ph\u1ED5 bi\u1EBFn s\u1EBD \u0111\u01B0\u1EE3c \u0111\u01B0a ra trong "),Dt=c("a"),we=s("Ch\u01B0\u01A1ng 7"),Ce=s(". N\u1EBFu b\u1EA1n mu\u1ED1n trau d\u1ED3i k\u1EF9 n\u0103ng c\u1EE7a m\xECnh tr\xEAn API Keras, h\xE3y c\u1ED1 g\u1EAFng tinh ch\u1EC9nh m\u1ED9t m\xF4 h\xECnh tr\xEAn t\u1EADp d\u1EEF li\u1EC7u GLUE SST-2, b\u1EB1ng c\xE1ch s\u1EED d\u1EE5ng x\u1EED l\xFD d\u1EEF li\u1EC7u b\u1EA1n \u0111\xE3 th\u1EF1c hi\u1EC7n trong ph\u1EA7n 2."),this.h()},l(t){const e=gs('[data-svelte="svelte-1phssyn"]',document.head);o=l(e,"META",{name:!0,content:!0}),e.forEach(h),C=u(t),y(p.$$.fragment,t),q=u(t),_=l(t,"H1",{class:!0});var qt=i(_);g=l(qt,"A",{id:!0,class:!0,href:!0});var un=i(g);w=l(un,"SPAN",{});var pn=i(w);y(j.$$.fragment,pn),pn.forEach(h),un.forEach(h),T=u(qt),f=l(qt,"SPAN",{});var gn=i(f);A=a(gn,"Tinh ch\u1EC9nh m\u1ED9t m\xF4 h\xECnh v\u1EDBi Keras"),gn.forEach(h),qt.forEach(h),P=u(t),y(N.$$.fragment,t),at=u(t),S=l(t,"P",{});var I=i(S);ih=a(I,"Khi b\u1EA1n \u0111\xE3 ho\xE0n th\xE0nh t\u1EA5t c\u1EA3 c\xF4ng vi\u1EC7c ti\u1EC1n x\u1EED l\xFD d\u1EEF li\u1EC7u trong ph\u1EA7n tr\u01B0\u1EDBc, b\u1EA1n ch\u1EC9 c\xF2n m\u1ED9t v\xE0i b\u01B0\u1EDBc n\u1EEFa \u0111\u1EC3 hu\u1EA5n luy\u1EC7n m\xF4 h\xECnh. Tuy nhi\xEAn, l\u01B0u \xFD r\u1EB1ng l\u1EC7nh "),Ot=l(I,"CODE",{});var qe=i(Ot);rh=a(qe,"model.fit()"),qe.forEach(h),oh=a(I," s\u1EBD ch\u1EA1y r\u1EA5t ch\u1EADm tr\xEAn CPU. N\u1EBFu b\u1EA1n ch\u01B0a thi\u1EBFt l\u1EADp GPU, b\u1EA1n c\xF3 th\u1EC3 c\xF3 quy\u1EC1n truy c\u1EADp v\xE0o GPU ho\u1EB7c TPU mi\u1EC5n ph\xED tr\xEAn "),ct=l(I,"A",{href:!0,rel:!0});var je=i(ct);mh=a(je,"Google Colab"),je.forEach(h),uh=a(I,"."),I.forEach(h),fn=u(t),jt=l(t,"P",{});var Te=i(jt);ph=a(Te,"C\xE1c \u0111o\u1EA1n m\xE3 v\xED d\u1EE5 b\xEAn d\u01B0\u1EDBi gi\u1EA3 s\u1EED b\u1EA1n \u0111\xE3 th\u1EF1c thi c\xE1c v\xED d\u1EE5 trong ph\u1EA7n tr\u01B0\u1EDBc. D\u01B0\u1EDBi \u0111\xE2y l\xE0 m\u1ED9t b\u1EA3n t\xF3m t\u1EAFt ng\u1EAFn g\u1ECDn t\xF3m t\u1EAFt l\u1EA1i nh\u1EEFng g\xEC b\u1EA1n c\u1EA7n:"),Te.forEach(h),dn=u(t),y(lt.$$.fragment,t),_n=u(t),U=l(t,"H3",{class:!0});var Zn=i(U);W=l(Zn,"A",{id:!0,class:!0,href:!0});var Pe=i(W);Bt=l(Pe,"SPAN",{});var xe=i(Bt);y(it.$$.fragment,xe),xe.forEach(h),Pe.forEach(h),gh=u(Zn),Gt=l(Zn,"SPAN",{});var Ae=i(Gt);fh=a(Ae,"Hu\u1EA5n luy\u1EC7n"),Ae.forEach(h),Zn.forEach(h),vn=u(t),Tt=l(t,"P",{});var ze=i(Tt);dh=a(ze,"C\xE1c m\xF4 h\xECnh TensorFlow nh\u1EADp t\u1EEB \u{1F917} Transformers v\u1ED1n l\xE0 c\xE1c m\xF4 h\xECnh Keras. \u0110\xE2y l\xE0 ph\u1EA7n gi\u1EDBi thi\u1EC7u ng\u1EAFn v\u1EC1 Keras."),ze.forEach(h),yn=u(t),y(rt.$$.fragment,t),$n=u(t),Pt=l(t,"P",{});var Se=i(Pt);_h=a(Se,"\u0110i\u1EC1u \u0111\xF3 c\xF3 ngh\u0129a l\xE0 m\u1ED9t khi ch\xFAng t\xF4i c\xF3 d\u1EEF li\u1EC7u ri\xEAng m\xECnh, ch\xFAng ta ch\u1EC9 c\u1EA7n thao t\xE1c \xEDt b\u01B0\u1EDBc n\u1EEFa th\xF4i \u0111\u1EC3 b\u1EAFt \u0111\u1EA7u hu\u1EA5n luy\u1EC7n."),Se.forEach(h),bn=u(t),y(ot.$$.fragment,t),kn=u(t),O=l(t,"P",{});var Kt=i(O);vh=a(Kt,"Nh\u01B0 trong "),xt=l(Kt,"A",{href:!0});var De=i(xt);yh=a(De,"ch\u01B0\u01A1ng tr\u01B0\u1EDBc"),De.forEach(h),$h=a(Kt,", ch\xFAng ta s\u1EBD s\u1EED d\u1EE5ng l\u1EDBp "),Lt=l(Kt,"CODE",{});var Ke=i(Lt);bh=a(Ke,"TFAutoModelForSequenceClassification"),Ke.forEach(h),kh=a(Kt,", v\u1EDBi hai nh\xE3n:"),Kt.forEach(h),En=u(t),y(mt.$$.fragment,t),wn=u(t),V=l(t,"P",{});var th=i(V);Eh=a(th,"B\u1EA1n s\u1EBD nh\u1EADn th\u1EA5y r\u1EB1ng kh\xF4ng nh\u01B0 trong "),At=l(th,"A",{href:!0});var Fe=i(At);wh=a(Fe,"Ch\u01B0\u01A1ng 2"),Fe.forEach(h),Ch=a(th,", b\u1EA1n nh\u1EADn \u0111\u01B0\u1EE3c m\u1ED9t c\u1EA3nh b\xE1o sau khi kh\u1EDFi t\u1EA1o m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc n\xE0y. \u0110\xE2y l\xE0 do BERT ch\u01B0a \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc v\u1EC1 ph\xE2n lo\u1EA1i c\xE1c c\u1EB7p c\xE2u, v\xEC v\u1EADy ph\u1EA7n \u0111\u1EA7u c\u1EE7a m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc \u0111\xE3 b\u1ECB lo\u1EA1i b\u1ECF v\xE0 ph\u1EA7n \u0111\u1EA7u m\u1EDBi ph\xF9 h\u1EE3p \u0111\u1EC3 ph\xE2n lo\u1EA1i chu\u1ED7i \u0111\xE3 \u0111\u01B0\u1EE3c ch\xE8n v\xE0o thay th\u1EBF. C\xE1c c\u1EA3nh b\xE1o ch\u1EC9 ra r\u1EB1ng m\u1ED9t s\u1ED1 tr\u1ECDng s\u1ED1 \u0111\xE3 kh\xF4ng \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng (nh\u1EEFng tr\u1ECDng s\u1ED1 t\u01B0\u01A1ng \u1EE9ng v\u1EDBi \u0111\u1EA7u hu\u1EA5n luy\u1EC7n tr\u01B0\u1EDBc b\u1ECB r\u1EE5ng) v\xE0 m\u1ED9t s\u1ED1 tr\u1ECDng s\u1ED1 kh\xE1c kh\xE1c \u0111\u01B0\u1EE3c kh\u1EDFi t\u1EA1o ng\u1EABu nhi\xEAn (nh\u1EEFng tr\u1ECDng s\u1ED1 d\xE0nh cho \u0111\u1EA7u m\u1EDBi). N\xF3 k\u1EBFt th\xFAc b\u1EB1ng c\xE1ch khuy\u1EBFn kh\xEDch b\u1EA1n hu\u1EA5n luy\u1EC7n m\xF4 h\xECnh, \u0111\xF3 ch\xEDnh x\xE1c l\xE0 nh\u1EEFng g\xEC ch\xFAng ta s\u1EBD l\xE0m b\xE2y gi\u1EDD."),th.forEach(h),Cn=u(t),B=l(t,"P",{});var Ft=i(B);qh=a(Ft,"\u0110\u1EC3 tinh ch\u1EC9nh m\xF4 h\xECnh tr\xEAn t\u1EADp d\u1EEF li\u1EC7u c\u1EE7a m\xECnh, ch\xFAng ta ch\u1EC9 c\u1EA7n "),Ut=l(Ft,"CODE",{});var Me=i(Ut);jh=a(Me,"compile()"),Me.forEach(h),Th=a(Ft," m\xF4 h\xECnh v\xE0 sau \u0111\xF3 chuy\u1EC3n d\u1EEF li\u1EC7u c\u1EE7a ta \u0111\u1EBFn ph\u01B0\u01A1ng th\u1EE9c "),Ht=l(Ft,"CODE",{});var Ne=i(Ht);Ph=a(Ne,"fit()"),Ne.forEach(h),xh=a(Ft,". Thao t\xE1c n\xE0y s\u1EBD b\u1EAFt \u0111\u1EA7u qu\xE1 tr\xECnh tinh ch\u1EC9nh (s\u1EBD m\u1EA5t v\xE0i ph\xFAt tr\xEAn GPU) v\xE0 b\xE1o c\xE1o s\u1EF1 m\u1EA5t m\xE1t \u1EDF t\u1EADp hu\u1EA5n luy\u1EC7n khi n\xF3 di\u1EC5n ra, c\u1ED9ng v\u1EDBi m\u1EA5t m\xE1t \u1EDF t\u1EADp ki\u1EC3m \u0111\u1ECBnh \u1EDF cu\u1ED1i m\u1ED7i epoch."),Ft.forEach(h),qn=u(t),y(Y.$$.fragment,t),jn=u(t),y(ut.$$.fragment,t),Tn=u(t),y(J.$$.fragment,t),Pn=u(t),H=l(t,"H3",{class:!0});var nh=i(H);Q=l(nh,"A",{id:!0,class:!0,href:!0});var Oe=i(Q);Rt=l(Oe,"SPAN",{});var Be=i(Rt);y(pt.$$.fragment,Be),Be.forEach(h),Oe.forEach(h),Ah=u(nh),It=l(nh,"SPAN",{});var Ge=i(It);zh=a(Ge,"C\u1EA3i thi\u1EC7n hi\u1EC7u su\u1EA5t hu\u1EA5n luy\u1EC7n"),Ge.forEach(h),nh.forEach(h),xn=u(t),y(gt.$$.fragment,t),An=u(t),G=l(t,"P",{});var Mt=i(G);Sh=a(Mt,"N\u1EBFu b\u1EA1n th\u1EED \u0111o\u1EA1n m\xE3 tr\xEAn, n\xF3 ch\u1EAFc ch\u1EAFn ch\u1EA1y, nh\u01B0ng b\u1EA1n s\u1EBD th\u1EA5y r\u1EB1ng h\xE0m m\u1EA5t m\xE1t ch\u1EC9 gi\u1EA3m t\u1EEB t\u1EEB ho\u1EB7c kh\xF4ng th\u01B0\u1EDDng xuy\xEAn. Nguy\xEAn nh\xE2n ch\xEDnh l\xE0 do "),Wt=l(Mt,"EM",{});var Le=i(Wt);Dh=a(Le,"learning rate"),Le.forEach(h),Kh=a(Mt," hay "),Vt=l(Mt,"EM",{});var Ue=i(Vt);Fh=a(Ue,"t\u1ED1c \u0111\u1ED9 h\u1ECDc"),Ue.forEach(h),Mh=a(Mt,`. V\u1EDBi h\xE0m m\u1EA5t m\xE1t, khi ta truy\u1EC1n cho Keras t\xEAn c\u1EE7a tr\xECnh t\u1ED1i \u01B0u h\xF3a d\u01B0\u1EDBi d\u1EA1ng m\u1ED9t chu\u1ED7i, Keras s\u1EBD kh\u1EDFi t\u1EA1o tr\xECnh t\u1ED1i \u01B0u h\xF3a \u0111\xF3 v\u1EDBi c\xE1c gi\xE1 tr\u1ECB m\u1EB7c \u0111\u1ECBnh cho t\u1EA5t c\u1EA3 c\xE1c tham s\u1ED1, bao g\u1ED3m c\u1EA3 t\u1ED1c \u0111\u1ED9 h\u1ECDc. Tuy nhi\xEAn, t\u1EEB kinh nghi\u1EC7m l\xE2u n\u0103m, ch\xFAng t\xF4i bi\u1EBFt
r\u1EB1ng c\xE1c m\xF4 h\xECnh Transformer \u0111\u01B0\u1EE3c h\u01B0\u1EDFng l\u1EE3i t\u1EEB t\u1ED1c \u0111\u1ED9 h\u1ECDc th\u1EA5p h\u01A1n nhi\u1EC1u so v\u1EDBi t\u1EF7 l\u1EC7 m\u1EB7c \u0111\u1ECBnh cho Adam, l\xE0 1e-3, c\u0169ng \u0111\u01B0\u1EE3c vi\u1EBFt b\u1EB1ng 10 l\u0169y th\u1EEBa c\u1EE7a -3, ho\u1EB7c 0,001. 5e-5 (0,00005), th\u1EA5p h\u01A1n kho\u1EA3ng hai m\u01B0\u01A1i l\u1EA7n, l\xE0 m\u1ED9t \u0111i\u1EC3m kh\u1EDFi \u0111\u1EA7u t\u1ED1t h\u01A1n nhi\u1EC1u.`),Mt.forEach(h),zn=u(t),x=l(t,"P",{});var z=i(x);Nh=a(z,"Ngo\xE0i vi\u1EC7c gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc, ch\xFAng t\xF4i c\xF3 m\u1ED9t m\u1EB9o th\u1EE9 hai: Ta c\xF3 th\u1EC3 t\u1EEB t\u1EEB gi\u1EA3m t\u1ED1c \u0111\u1ED9 h\u1ECDc trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n. Trong t\xE0i li\u1EC7u, \u0111\xF4i khi b\u1EA1n s\u1EBD th\u1EA5y \u0111i\u1EC1u n\xE0y \u0111\u01B0\u1EE3c g\u1ECDi l\xE0 "),Yt=l(z,"EM",{});var He=i(Yt);Oh=a(He,"ph\xE2n r\xE3"),He.forEach(h),Bh=a(z," ho\u1EB7c "),Jt=l(z,"EM",{});var Re=i(Jt);Gh=a(Re,"\u1EE7"),Re.forEach(h),Lh=a(z," t\u1ED1c \u0111\u1ED9 h\u1ECDc. \u1EDE Keras, c\xE1ch t\u1ED1t nh\u1EA5t \u0111\u1EC3 l\xE0m \u0111i\u1EC1u n\xE0y l\xE0 s\u1EED d\u1EE5ng "),Qt=l(z,"EM",{});var Ie=i(Qt);Uh=a(Ie,"learning rate scheduler"),Ie.forEach(h),Hh=a(z," hay "),Xt=l(z,"EM",{});var We=i(Xt);Rh=a(We,"c\xF4ng c\u1EE5 l\u1EADp l\u1ECBch tr\xECnh t\u1ED1c \u0111\u1ED9 h\u1ECDc"),We.forEach(h),Ih=a(z,". M\u1ED9t c\xE1i hay \u0111\u1EC3 s\u1EED d\u1EE5ng l\xE0 "),Zt=l(z,"CODE",{});var Ve=i(Zt);Wh=a(Ve,"PolynomialDecay"),Ve.forEach(h),Vh=a(z," - v\u1EDBi c\xE0i \u0111\u1EB7t m\u1EB7c \u0111\u1ECBnh, n\xF3 ch\u1EC9 \u0111\u01A1n gi\u1EA3n l\xE0 gi\u1EA3m \u0111\u1ED9 tuy\u1EBFn t\xEDnh t\u1ED1c \u0111\u1ED9 h\u1ECDc t\u1EEB gi\xE1 tr\u1ECB ban \u0111\u1EA7u \u0111\u1EBFn gi\xE1 tr\u1ECB cu\u1ED1i c\xF9ng trong qu\xE1 tr\xECnh hu\u1EA5n luy\u1EC7n, \u0111\xF3 ch\xEDnh x\xE1c l\xE0 nh\u1EEFng g\xEC ta mu\u1ED1n. Tuy nhi\xEAn, \u0111\u1EC3 s\u1EED d\u1EE5ng b\u1ED9 l\u1EADp l\u1ECBch m\u1ED9t c\xE1ch ch\xEDnh x\xE1c, ch\xFAng ta c\u1EA7n cho n\xF3 bi\u1EBFt th\u1EDDi gian hu\u1EA5n luy\u1EC7n s\u1EBD k\xE9o d\xE0i. Ch\xFAng ta t\xEDnh gi\xE1 tr\u1ECB \u0111\xF3 d\u01B0\u1EDBi d\u1EA1ng "),tn=l(z,"CODE",{});var Ye=i(tn);Yh=a(Ye,"num_train_steps"),Ye.forEach(h),Jh=a(z," nh\u01B0 sau."),z.forEach(h),Sn=u(t),y(ft.$$.fragment,t),Dn=u(t),y(X.$$.fragment,t),Kn=u(t),zt=l(t,"P",{});var Je=i(zt);Qh=a(Je,"B\xE2y gi\u1EDD ch\xFAng ta \u0111\xE3 c\xF3 tr\xECnh t\u1ED1i \u01B0u h\xF3a ho\xE0n to\xE0n m\u1EDBi v\xE0 ta c\xF3 th\u1EC3 th\u1EED hu\u1EA5n luy\u1EC7n v\u1EDBi n\xF3. \u0110\u1EA7u ti\xEAn, h\xE3y t\u1EA3i l\u1EA1i m\xF4 h\xECnh, \u0111\u1EC3 \u0111\u1EB7t l\u1EA1i c\xE1c thay \u0111\u1ED5i \u0111\u1ED1i v\u1EDBi tr\u1ECDng s\u1ED1 t\u1EEB l\u1EA7n ch\u1EA1y hu\u1EA5n luy\u1EC7n m\xE0 ch\xFAng ta v\u1EEBa th\u1EF1c hi\u1EC7n v\xE0 sau \u0111\xF3 ta c\xF3 th\u1EC3 bi\xEAn d\u1ECBch n\xF3 b\u1EB1ng tr\xECnh t\u1ED1i \u01B0u h\xF3a m\u1EDBi:"),Je.forEach(h),Fn=u(t),y(dt.$$.fragment,t),Mn=u(t),St=l(t,"P",{});var Qe=i(St);Xh=a(Qe,"Gi\u1EDD ta s\u1EBD fit l\u1EA1i 1 l\u1EA7n n\u1EEFa:"),Qe.forEach(h),Nn=u(t),y(_t.$$.fragment,t),On=u(t),y(Z.$$.fragment,t),Bn=u(t),R=l(t,"H3",{class:!0});var hh=i(R);tt=l(hh,"A",{id:!0,class:!0,href:!0});var Xe=i(tt);nn=l(Xe,"SPAN",{});var Ze=i(nn);y(vt.$$.fragment,Ze),Ze.forEach(h),Xe.forEach(h),Zh=u(hh),hn=l(hh,"SPAN",{});var ts=i(hn);te=a(ts,"C\xE1c d\u1EF1 \u0111o\xE1n c\u1EE7a m\xF4 h\xECnh"),ts.forEach(h),hh.forEach(h),Gn=u(t),y(yt.$$.fragment,t),Ln=u(t),L=l(t,"P",{});var Nt=i(L);ne=a(Nt,"Vi\u1EC7c hu\u1EA5n luy\u1EC7n v\xE0 theo d\xF5i s\u1EF1 m\u1EA5t m\xE1t gi\u1EA3m xu\u1ED1ng \u0111\u1EC1u r\u1EA5t t\u1ED1t, nh\u01B0ng n\u1EBFu ch\xFAng ta mu\u1ED1n th\u1EF1c s\u1EF1 c\xF3 \u0111\u01B0\u1EE3c k\u1EBFt qu\u1EA3 \u0111\u1EA7u ra t\u1EEB m\xF4 h\xECnh \u0111\u01B0\u1EE3c hu\u1EA5n luy\u1EC7n, \u0111\u1EC3 t\xEDnh to\xE1n m\u1ED9t s\u1ED1 ch\u1EC9 s\u1ED1 ho\u1EB7c s\u1EED d\u1EE5ng m\xF4 h\xECnh \u0111\xF3 trong s\u1EA3n xu\u1EA5t th\xEC sao? \u0110\u1EC3 l\xE0m \u0111i\u1EC1u \u0111\xF3, ch\xFAng ta ch\u1EC9 c\xF3 th\u1EC3 s\u1EED d\u1EE5ng ph\u01B0\u01A1ng th\u1EE9c "),en=l(Nt,"CODE",{});var ns=i(en);he=a(ns,"predict()"),ns.forEach(h),ee=a(Nt,". \u0110i\u1EC1u n\xE0y s\u1EBD tr\u1EA3 v\u1EC1 "),sn=l(Nt,"EM",{});var hs=i(sn);se=a(hs,"logit"),hs.forEach(h),ae=a(Nt," t\u1EEB \u0111\u1EA7u ra c\u1EE7a m\xF4 h\xECnh, m\u1ED9t cho m\u1ED7i l\u1EDBp."),Nt.forEach(h),Un=u(t),y($t.$$.fragment,t),Hn=u(t),nt=l(t,"P",{});var eh=i(nt);ce=a(eh,"Ch\xFAng ta c\xF3 th\u1EC3 chuy\u1EC3n \u0111\u1ED5i c\xE1c logit n\xE0y th\xE0nh c\xE1c d\u1EF1 \u0111o\xE1n l\u1EDBp c\u1EE7a m\xF4 h\xECnh b\u1EB1ng c\xE1ch s\u1EED d\u1EE5ng "),an=l(eh,"CODE",{});var es=i(an);le=a(es,"argmax"),es.forEach(h),ie=a(eh," \u0111\u1EC3 t\xECm logit cao nh\u1EA5t, t\u01B0\u01A1ng \u1EE9ng v\u1EDBi l\u1EDBp c\xF3 nhi\u1EC1u kh\u1EA3 n\u0103ng nh\u1EA5t:"),eh.forEach(h),Rn=u(t),y(bt.$$.fragment,t),In=u(t),y(kt.$$.fragment,t),Wn=u(t),D=l(t,"P",{});var et=i(D);re=a(et,"B\xE2y gi\u1EDD, h\xE3y s\u1EED d\u1EE5ng c\xE1c "),cn=l(et,"CODE",{});var ss=i(cn);oe=a(ss,"preds"),ss.forEach(h),me=a(et," \u0111\xF3 \u0111\u1EC3 t\xEDnh to\xE1n m\u1ED9t s\u1ED1 ch\u1EC9 s\u1ED1! Ch\xFAng ta c\xF3 th\u1EC3 t\u1EA3i c\xE1c ch\u1EC9 s\u1ED1 \u0111\u01B0\u1EE3c li\xEAn k\u1EBFt v\u1EDBi t\u1EADp d\u1EEF li\u1EC7u MRPC d\u1EC5 d\xE0ng nh\u01B0 khi ta t\u1EA3i t\u1EADp d\u1EEF li\u1EC7u, l\u1EA7n n\xE0y l\xE0 v\u1EDBi h\xE0m "),ln=l(et,"CODE",{});var as=i(ln);ue=a(as,"eval.load())"),as.forEach(h),pe=a(et,". \u0110\u1ED1i t\u01B0\u1EE3ng \u0111\u01B0\u1EE3c tr\u1EA3 v\u1EC1 c\xF3 ph\u01B0\u01A1ng th\u1EE9c "),rn=l(et,"CODE",{});var cs=i(rn);ge=a(cs,"compute()"),cs.forEach(h),fe=a(et," m\xE0 ch\xFAng ta c\xF3 th\u1EC3 s\u1EED d\u1EE5ng \u0111\u1EC3 th\u1EF1c hi\u1EC7n ph\xE9p t\xEDnh s\u1ED1 li\u1EC7u:"),et.forEach(h),Vn=u(t),y(Et.$$.fragment,t),Yn=u(t),y(wt.$$.fragment,t),Jn=u(t),K=l(t,"P",{});var st=i(K);de=a(st,"K\u1EBFt qu\u1EA3 ch\xEDnh x\xE1c b\u1EA1n nh\u1EADn \u0111\u01B0\u1EE3c c\xF3 th\u1EC3 kh\xE1c nhau, v\xEC vi\u1EC7c kh\u1EDFi t\u1EA1o ng\u1EABu nhi\xEAn ph\u1EA7n \u0111\u1EA7u m\xF4 h\xECnh c\xF3 th\u1EC3 thay \u0111\u1ED5i c\xE1c ch\u1EC9 s\u1ED1 m\xE0 n\xF3 \u0111\u1EA1t \u0111\u01B0\u1EE3c. \u1EDE \u0111\xE2y, ch\xFAng ta c\xF3 th\u1EC3 th\u1EA5y m\xF4 h\xECnh c\xF3 \u0111\u1ED9 ch\xEDnh x\xE1c 85.78% tr\xEAn t\u1EADp ki\u1EC3m \u0111\u1ECBnh v\xE0 \u0111i\u1EC3m F1 l\xE0 89.97. \u0110\xF3 l\xE0 hai ch\u1EC9 s\u1ED1 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng \u0111\u1EC3 \u0111\xE1nh gi\xE1 k\u1EBFt qu\u1EA3 tr\xEAn t\u1EADp d\u1EEF li\u1EC7u MRPC theo \u0111i\u1EC3m chu\u1EA9n GLUE. B\u1EA3ng trong "),Ct=l(st,"A",{href:!0,rel:!0});var ls=i(Ct);_e=a(ls,"b\xE0i b\xE1o BERT"),ls.forEach(h),ve=a(st," b\xE1o c\xE1o \u0111i\u1EC3m F1 l\xE0 88.9 cho m\xF4 h\xECnh c\u01A1 s\u1EDF. \u0110\xF3 l\xE0 m\xF4 h\xECnh "),on=l(st,"CODE",{});var is=i(on);ye=a(is,"kh\xF4ng ph\xE2n bi\u1EC7t"),is.forEach(h),$e=a(st," vi\u1EBFt hoa vi\u1EBFt th\u01B0\u1EDDng trong khi ch\xFAng ta hi\u1EC7n \u0111ang s\u1EED d\u1EE5ng m\xF4 h\xECnh "),mn=l(st,"CODE",{});var rs=i(mn);be=a(rs,"c\xF3 ph\xE2n bi\u1EC7t"),rs.forEach(h),ke=a(st,", \u0111i\u1EC1u n\xE0y gi\u1EA3i th\xEDch k\u1EBFt qu\u1EA3 t\u1ED1t h\u01A1n."),st.forEach(h),Qn=u(t),ht=l(t,"P",{});var sh=i(ht);Ee=a(sh,"Ph\u1EA7n n\xE0y k\u1EBFt th\xFAc ph\u1EA7n gi\u1EDBi thi\u1EC7u v\u1EC1 c\xE1ch tinh ch\u1EC9nh b\u1EB1ng Keras API. M\u1ED9t v\xED d\u1EE5 v\u1EC1 c\xE1ch l\xE0m n\xE0y \u0111\u1ED1i v\u1EDBi h\u1EA7u h\u1EBFt c\xE1c t\xE1c v\u1EE5 NLP ph\u1ED5 bi\u1EBFn s\u1EBD \u0111\u01B0\u1EE3c \u0111\u01B0a ra trong "),Dt=l(sh,"A",{href:!0});var os=i(Dt);we=a(os,"Ch\u01B0\u01A1ng 7"),os.forEach(h),Ce=a(sh,". N\u1EBFu b\u1EA1n mu\u1ED1n trau d\u1ED3i k\u1EF9 n\u0103ng c\u1EE7a m\xECnh tr\xEAn API Keras, h\xE3y c\u1ED1 g\u1EAFng tinh ch\u1EC9nh m\u1ED9t m\xF4 h\xECnh tr\xEAn t\u1EADp d\u1EEF li\u1EC7u GLUE SST-2, b\u1EB1ng c\xE1ch s\u1EED d\u1EE5ng x\u1EED l\xFD d\u1EEF li\u1EC7u b\u1EA1n \u0111\xE3 th\u1EF1c hi\u1EC7n trong ph\u1EA7n 2."),sh.forEach(h),this.h()},h(){d(o,"name","hf:doc:metadata"),d(o,"content",JSON.stringify(Es)),d(g,"id","tinh-chnh-mt-m-hnh-vi-keras"),d(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(g,"href","#tinh-chnh-mt-m-hnh-vi-keras"),d(_,"class","relative group"),d(ct,"href","https://colab.research.google.com/"),d(ct,"rel","nofollow"),d(W,"id","hun-luyn"),d(W,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(W,"href","#hun-luyn"),d(U,"class","relative group"),d(xt,"href","/course/chapter2"),d(At,"href","/course/chapter2"),d(Q,"id","ci-thin-hiu-sut-hun-luyn"),d(Q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Q,"href","#ci-thin-hiu-sut-hun-luyn"),d(H,"class","relative group"),d(tt,"id","cc-d-on-ca-m-hnh"),d(tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(tt,"href","#cc-d-on-ca-m-hnh"),d(R,"class","relative group"),d(Ct,"href","https://arxiv.org/pdf/1810.04805.pdf"),d(Ct,"rel","nofollow"),d(Dt,"href","/course/chapter7")},m(t,e){n(document.head,o),r(t,C,e),$(p,t,e),r(t,q,e),r(t,_,e),n(_,g),n(g,w),$(j,w,null),n(_,T),n(_,f),n(f,A),r(t,P,e),$(N,t,e),r(t,at,e),r(t,S,e),n(S,ih),n(S,Ot),n(Ot,rh),n(S,oh),n(S,ct),n(ct,mh),n(S,uh),r(t,fn,e),r(t,jt,e),n(jt,ph),r(t,dn,e),$(lt,t,e),r(t,_n,e),r(t,U,e),n(U,W),n(W,Bt),$(it,Bt,null),n(U,gh),n(U,Gt),n(Gt,fh),r(t,vn,e),r(t,Tt,e),n(Tt,dh),r(t,yn,e),$(rt,t,e),r(t,$n,e),r(t,Pt,e),n(Pt,_h),r(t,bn,e),$(ot,t,e),r(t,kn,e),r(t,O,e),n(O,vh),n(O,xt),n(xt,yh),n(O,$h),n(O,Lt),n(Lt,bh),n(O,kh),r(t,En,e),$(mt,t,e),r(t,wn,e),r(t,V,e),n(V,Eh),n(V,At),n(At,wh),n(V,Ch),r(t,Cn,e),r(t,B,e),n(B,qh),n(B,Ut),n(Ut,jh),n(B,Th),n(B,Ht),n(Ht,Ph),n(B,xh),r(t,qn,e),$(Y,t,e),r(t,jn,e),$(ut,t,e),r(t,Tn,e),$(J,t,e),r(t,Pn,e),r(t,H,e),n(H,Q),n(Q,Rt),$(pt,Rt,null),n(H,Ah),n(H,It),n(It,zh),r(t,xn,e),$(gt,t,e),r(t,An,e),r(t,G,e),n(G,Sh),n(G,Wt),n(Wt,Dh),n(G,Kh),n(G,Vt),n(Vt,Fh),n(G,Mh),r(t,zn,e),r(t,x,e),n(x,Nh),n(x,Yt),n(Yt,Oh),n(x,Bh),n(x,Jt),n(Jt,Gh),n(x,Lh),n(x,Qt),n(Qt,Uh),n(x,Hh),n(x,Xt),n(Xt,Rh),n(x,Ih),n(x,Zt),n(Zt,Wh),n(x,Vh),n(x,tn),n(tn,Yh),n(x,Jh),r(t,Sn,e),$(ft,t,e),r(t,Dn,e),$(X,t,e),r(t,Kn,e),r(t,zt,e),n(zt,Qh),r(t,Fn,e),$(dt,t,e),r(t,Mn,e),r(t,St,e),n(St,Xh),r(t,Nn,e),$(_t,t,e),r(t,On,e),$(Z,t,e),r(t,Bn,e),r(t,R,e),n(R,tt),n(tt,nn),$(vt,nn,null),n(R,Zh),n(R,hn),n(hn,te),r(t,Gn,e),$(yt,t,e),r(t,Ln,e),r(t,L,e),n(L,ne),n(L,en),n(en,he),n(L,ee),n(L,sn),n(sn,se),n(L,ae),r(t,Un,e),$($t,t,e),r(t,Hn,e),r(t,nt,e),n(nt,ce),n(nt,an),n(an,le),n(nt,ie),r(t,Rn,e),$(bt,t,e),r(t,In,e),$(kt,t,e),r(t,Wn,e),r(t,D,e),n(D,re),n(D,cn),n(cn,oe),n(D,me),n(D,ln),n(ln,ue),n(D,pe),n(D,rn),n(rn,ge),n(D,fe),r(t,Vn,e),$(Et,t,e),r(t,Yn,e),$(wt,t,e),r(t,Jn,e),r(t,K,e),n(K,de),n(K,Ct),n(Ct,_e),n(K,ve),n(K,on),n(on,ye),n(K,$e),n(K,mn),n(mn,be),n(K,ke),r(t,Qn,e),r(t,ht,e),n(ht,Ee),n(ht,Dt),n(Dt,we),n(ht,Ce),Xn=!0},p(t,[e]){const qt={};e&1&&(qt.fw=t[0]),p.$set(qt);const un={};e&2&&(un.$$scope={dirty:e,ctx:t}),Y.$set(un);const pn={};e&2&&(pn.$$scope={dirty:e,ctx:t}),J.$set(pn);const gn={};e&2&&(gn.$$scope={dirty:e,ctx:t}),X.$set(gn);const I={};e&2&&(I.$$scope={dirty:e,ctx:t}),Z.$set(I)},i(t){Xn||(b(p.$$.fragment,t),b(j.$$.fragment,t),b(N.$$.fragment,t),b(lt.$$.fragment,t),b(it.$$.fragment,t),b(rt.$$.fragment,t),b(ot.$$.fragment,t),b(mt.$$.fragment,t),b(Y.$$.fragment,t),b(ut.$$.fragment,t),b(J.$$.fragment,t),b(pt.$$.fragment,t),b(gt.$$.fragment,t),b(ft.$$.fragment,t),b(X.$$.fragment,t),b(dt.$$.fragment,t),b(_t.$$.fragment,t),b(Z.$$.fragment,t),b(vt.$$.fragment,t),b(yt.$$.fragment,t),b($t.$$.fragment,t),b(bt.$$.fragment,t),b(kt.$$.fragment,t),b(Et.$$.fragment,t),b(wt.$$.fragment,t),Xn=!0)},o(t){k(p.$$.fragment,t),k(j.$$.fragment,t),k(N.$$.fragment,t),k(lt.$$.fragment,t),k(it.$$.fragment,t),k(rt.$$.fragment,t),k(ot.$$.fragment,t),k(mt.$$.fragment,t),k(Y.$$.fragment,t),k(ut.$$.fragment,t),k(J.$$.fragment,t),k(pt.$$.fragment,t),k(gt.$$.fragment,t),k(ft.$$.fragment,t),k(X.$$.fragment,t),k(dt.$$.fragment,t),k(_t.$$.fragment,t),k(Z.$$.fragment,t),k(vt.$$.fragment,t),k(yt.$$.fragment,t),k($t.$$.fragment,t),k(bt.$$.fragment,t),k(kt.$$.fragment,t),k(Et.$$.fragment,t),k(wt.$$.fragment,t),Xn=!1},d(t){h(o),t&&h(C),E(p,t),t&&h(q),t&&h(_),E(j),t&&h(P),E(N,t),t&&h(at),t&&h(S),t&&h(fn),t&&h(jt),t&&h(dn),E(lt,t),t&&h(_n),t&&h(U),E(it),t&&h(vn),t&&h(Tt),t&&h(yn),E(rt,t),t&&h($n),t&&h(Pt),t&&h(bn),E(ot,t),t&&h(kn),t&&h(O),t&&h(En),E(mt,t),t&&h(wn),t&&h(V),t&&h(Cn),t&&h(B),t&&h(qn),E(Y,t),t&&h(jn),E(ut,t),t&&h(Tn),E(J,t),t&&h(Pn),t&&h(H),E(pt),t&&h(xn),E(gt,t),t&&h(An),t&&h(G),t&&h(zn),t&&h(x),t&&h(Sn),E(ft,t),t&&h(Dn),E(X,t),t&&h(Kn),t&&h(zt),t&&h(Fn),E(dt,t),t&&h(Mn),t&&h(St),t&&h(Nn),E(_t,t),t&&h(On),E(Z,t),t&&h(Bn),t&&h(R),E(vt),t&&h(Gn),E(yt,t),t&&h(Ln),t&&h(L),t&&h(Un),E($t,t),t&&h(Hn),t&&h(nt),t&&h(Rn),E(bt,t),t&&h(In),E(kt,t),t&&h(Wn),t&&h(D),t&&h(Vn),E(Et,t),t&&h(Yn),E(wt,t),t&&h(Jn),t&&h(K),t&&h(Qn),t&&h(ht)}}}const Es={local:"tinh-chnh-mt-m-hnh-vi-keras",sections:[{local:"hun-luyn",title:"Hu\u1EA5n luy\u1EC7n"},{local:"ci-thin-hiu-sut-hun-luyn",title:"C\u1EA3i thi\u1EC7n hi\u1EC7u su\u1EA5t hu\u1EA5n luy\u1EC7n"},{local:"cc-d-on-ca-m-hnh",title:"C\xE1c d\u1EF1 \u0111o\xE1n c\u1EE7a m\xF4 h\xECnh"}],title:"Tinh ch\u1EC9nh m\u1ED9t m\xF4 h\xECnh v\u1EDBi Keras"};function ws(F,o,C){let p="pt";return fs(()=>{const q=new URLSearchParams(window.location.search);C(0,p=q.get("fw")||"pt")}),[p]}class Ss extends ms{constructor(o){super();us(this,o,ws,ks,ps,{})}}export{Ss as default,Es as metadata};
