Buckets:

rtrm's picture
download
raw
109 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Trainer API ဖြင့် မော်ဒယ်တစ်ခုကို Fine-tuning လုပ်ခြင်း&quot;,&quot;local&quot;:&quot;fine-tuning-a-model-with-the-trainer-api&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Training&quot;,&quot;local&quot;:&quot;training&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Evaluation&quot;,&quot;local&quot;:&quot;evaluation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Advanced Training Features&quot;,&quot;local&quot;:&quot;advanced-training-features&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း&quot;,&quot;local&quot;:&quot;section-quiz&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;1. Trainer မှာပါတဲ့ processing_class parameter ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;1-trainer-မပတ-processingclass-parameter-ရ-ရညရယခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;2. TrainingArguments parameter က training လုပ်နေစဉ် evaluation ကို ဘယ်လောက်ကြာကြာ လုပ်ရမယ်ဆိုတာကို ဘယ်လိုထိန်းချုပ်သလဲ။&quot;,&quot;local&quot;:&quot;2-trainingarguments-parameter-က-training-လပနစဉ-evaluation-က-ဘယလကကက-လပရမယဆတက-ဘယလထနခပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;3. TrainingArguments မှာ fp16=True က ဘာကို ဖွင့်ပေးသလဲ။&quot;,&quot;local&quot;:&quot;3-trainingarguments-မ-fp16true-က-ဘက-ဖငပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;4. Trainer မှာပါတဲ့ compute_metrics function ရဲ့ အခန်းကဏ္ဍက ဘာလဲ။&quot;,&quot;local&quot;:&quot;4-trainer-မပတ-computemetrics-function-ရ-အခနကဏဍက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;5. Trainer ကို eval_dataset မပေးတဲ့အခါ ဘာဖြစ်မလဲ။&quot;,&quot;local&quot;:&quot;5-trainer-က-evaldataset-မပတအခ-ဘဖစမလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;6. Gradient accumulation ဆိုတာ ဘာလဲ၊ ဘယ်လို ဖွင့်ရမလဲ။&quot;,&quot;local&quot;:&quot;6-gradient-accumulation-ဆတ-ဘလ-ဘယလ-ဖငရမလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ဝေါဟာရ ရှင်းလင်းချက် (Glossary)&quot;,&quot;local&quot;:&quot;ဝဟရ-ရငလငခက-glossary&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/course/pr_1114/my/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/entry/start.14794ee9.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/scheduler.893fe8c9.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/singletons.10fda3ce.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/index.bce52c8a.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/paths.89c82153.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/entry/app.a133f5c6.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/preload-helper.b1a719fd.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/index.b1df2166.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/nodes/0.510afdc1.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/nodes/25.9438cae0.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.762ed9cc.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/Youtube.ec5d7916.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/CodeBlock.6cef0479.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/CourseFloatingBanner.c1c08878.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/Question.ea6d4cb0.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/stores.db603902.js">
<link rel="modulepreload" href="/docs/course/pr_1114/my/_app/immutable/chunks/FrameworkSwitchCourse.4480e339.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Trainer API ဖြင့် မော်ဒယ်တစ်ခုကို Fine-tuning လုပ်ခြင်း&quot;,&quot;local&quot;:&quot;fine-tuning-a-model-with-the-trainer-api&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Training&quot;,&quot;local&quot;:&quot;training&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Evaluation&quot;,&quot;local&quot;:&quot;evaluation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Advanced Training Features&quot;,&quot;local&quot;:&quot;advanced-training-features&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း&quot;,&quot;local&quot;:&quot;section-quiz&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;1. Trainer မှာပါတဲ့ processing_class parameter ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;1-trainer-မပတ-processingclass-parameter-ရ-ရညရယခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;2. TrainingArguments parameter က training လုပ်နေစဉ် evaluation ကို ဘယ်လောက်ကြာကြာ လုပ်ရမယ်ဆိုတာကို ဘယ်လိုထိန်းချုပ်သလဲ။&quot;,&quot;local&quot;:&quot;2-trainingarguments-parameter-က-training-လပနစဉ-evaluation-က-ဘယလကကက-လပရမယဆတက-ဘယလထနခပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;3. TrainingArguments မှာ fp16=True က ဘာကို ဖွင့်ပေးသလဲ။&quot;,&quot;local&quot;:&quot;3-trainingarguments-မ-fp16true-က-ဘက-ဖငပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;4. Trainer မှာပါတဲ့ compute_metrics function ရဲ့ အခန်းကဏ္ဍက ဘာလဲ။&quot;,&quot;local&quot;:&quot;4-trainer-မပတ-computemetrics-function-ရ-အခနကဏဍက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;5. Trainer ကို eval_dataset မပေးတဲ့အခါ ဘာဖြစ်မလဲ။&quot;,&quot;local&quot;:&quot;5-trainer-က-evaldataset-မပတအခ-ဘဖစမလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;6. Gradient accumulation ဆိုတာ ဘာလဲ၊ ဘယ်လို ဖွင့်ရမလဲ။&quot;,&quot;local&quot;:&quot;6-gradient-accumulation-ဆတ-ဘလ-ဘယလ-ဖငရမလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ဝေါဟာရ ရှင်းလင်းချက် (Glossary)&quot;,&quot;local&quot;:&quot;ဝဟရ-ရငလငခက-glossary&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="bg-white leading-none border border-gray-100 rounded-lg flex p-0.5 w-56 text-sm mb-4"><a class="flex justify-center flex-1 py-1.5 px-2.5 focus:outline-none !no-underline rounded-l bg-red-50 dark:bg-transparent text-red-600" href="?fw=pt"><svg class="mr-1.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><defs><clipPath id="a"><rect x="3.05" y="0.5" width="25.73" height="31" fill="none"></rect></clipPath></defs><g clip-path="url(#a)"><path d="M24.94,9.51a12.81,12.81,0,0,1,0,18.16,12.68,12.68,0,0,1-18,0,12.81,12.81,0,0,1,0-18.16l9-9V5l-.84.83-6,6a9.58,9.58,0,1,0,13.55,0ZM20.44,9a1.68,1.68,0,1,1,1.67-1.67A1.68,1.68,0,0,1,20.44,9Z" fill="#ee4c2c"></path></g></svg> Pytorch </a><a class="flex justify-center flex-1 py-1.5 px-2.5 focus:outline-none !no-underline rounded-r text-gray-500 filter grayscale" href="?fw=tf"><svg class="mr-1.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="0.94em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 274"><path d="M145.726 42.065v42.07l72.861 42.07v-42.07l-72.86-42.07zM0 84.135v42.07l36.43 21.03V105.17L0 84.135zm109.291 21.035l-36.43 21.034v126.2l36.43 21.035v-84.135l36.435 21.035v-42.07l-36.435-21.034V105.17z" fill="#E55B2D"></path><path d="M145.726 42.065L36.43 105.17v42.065l72.861-42.065v42.065l36.435-21.03v-84.14zM255.022 63.1l-36.435 21.035v42.07l36.435-21.035V63.1zm-72.865 84.135l-36.43 21.035v42.07l36.43-21.036v-42.07zm-36.43 63.104l-36.436-21.035v84.135l36.435-21.035V210.34z" fill="#ED8E24"></path><path d="M145.726 0L0 84.135l36.43 21.035l109.296-63.105l72.861 42.07L255.022 63.1L145.726 0zm0 126.204l-36.435 21.03l36.435 21.036l36.43-21.035l-36.43-21.03z" fill="#F8BF3C"></path></svg> TensorFlow </a></div> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 max-sm:gap-0.5 h-6 max-sm:h-5 px-2 max-sm:px-1.5 text-[11px] max-sm:text-[9px] font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0"><svg class="w-3 h-3 max-sm:w-2.5 max-sm:h-2.5" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-6 max-sm:h-5 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible w-3 h-3 max-sm:w-2.5 max-sm:h-2.5 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="fine-tuning-a-model-with-the-trainer-api" 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" href="#fine-tuning-a-model-with-the-trainer-api"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Trainer API ဖြင့် မော်ဒယ်တစ်ခုကို Fine-tuning လုပ်ခြင်း</span></h1> <div class="flex space-x-1 absolute z-10 right-0 top-0" style=""><a href="https://discuss.huggingface.co/t/chapter-3-questions" target="_blank"><img alt="Ask a Question" class="!m-0" src="https://img.shields.io/badge/Ask%20a%20question-ffcb4c.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgLTEgMTA0IDEwNiI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiMyMzFmMjA7fS5jbHMtMntmaWxsOiNmZmY5YWU7fS5jbHMtM3tmaWxsOiMwMGFlZWY7fS5jbHMtNHtmaWxsOiMwMGE5NGY7fS5jbHMtNXtmaWxsOiNmMTVkMjI7fS5jbHMtNntmaWxsOiNlMzFiMjM7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5EaXNjb3Vyc2VfbG9nbzwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiPjxnIGlkPSJMYXllcl8zIj48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik01MS44NywwQzIzLjcxLDAsMCwyMi44MywwLDUxYzAsLjkxLDAsNTIuODEsMCw1Mi44MWw1MS44Ni0uMDVjMjguMTYsMCw1MS0yMy43MSw1MS01MS44N1M4MCwwLDUxLjg3LDBaIi8+PHBhdGggY2xhc3M9ImNscy0yIiBkPSJNNTIuMzcsMTkuNzRBMzEuNjIsMzEuNjIsMCwwLDAsMjQuNTgsNjYuNDFsLTUuNzIsMTguNEwzOS40LDgwLjE3YTMxLjYxLDMxLjYxLDAsMSwwLDEzLTYwLjQzWiIvPjxwYXRoIGNsYXNzPSJjbHMtMyIgZD0iTTc3LjQ1LDMyLjEyYTMxLjYsMzEuNiwwLDAsMS0zOC4wNSw0OEwxOC44Niw4NC44MmwyMC45MS0yLjQ3QTMxLjYsMzEuNiwwLDAsMCw3Ny40NSwzMi4xMloiLz48cGF0aCBjbGFzcz0iY2xzLTQiIGQ9Ik03MS42MywyNi4yOUEzMS42LDMxLjYsMCwwLDEsMzguOCw3OEwxOC44Niw4NC44MiwzOS40LDgwLjE3QTMxLjYsMzEuNiwwLDAsMCw3MS42MywyNi4yOVoiLz48cGF0aCBjbGFzcz0iY2xzLTUiIGQ9Ik0yNi40Nyw2Ny4xMWEzMS42MSwzMS42MSwwLDAsMSw1MS0zNUEzMS42MSwzMS42MSwwLDAsMCwyNC41OCw2Ni40MWwtNS43MiwxOC40WiIvPjxwYXRoIGNsYXNzPSJjbHMtNiIgZD0iTTI0LjU4LDY2LjQxQTMxLjYxLDMxLjYxLDAsMCwxLDcxLjYzLDI2LjI5YTMxLjYxLDMxLjYxLDAsMCwwLTQ5LDM5LjYzbC0zLjc2LDE4LjlaIi8+PC9nPjwvZz48L3N2Zz4="></a> <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter3/section3.ipynb" target="_blank"><img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"></a> <a href="https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter3/section3.ipynb" target="_blank"><img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"></a></div> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/nvBXf7s7vTI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-gjqzux">🤗 Transformers က ပံ့ပိုးပေးထားတဲ့ pretrained models တွေကို သင်ရဲ့ dataset ပေါ်မှာ ခေတ်မီ အကောင်းဆုံးနည်းလမ်းများနဲ့ fine-tune လုပ်ဖို့ <code>Trainer</code> class တစ်ခုကို ပေးစွမ်းပါတယ်။ ယခင်အပိုင်းမှာ ဒေတာ preprocessing လုပ်ငန်းအားလုံးကို လုပ်ဆောင်ပြီးသွားရင်၊ <code>Trainer</code> ကို သတ်မှတ်ဖို့ အနည်းငယ်သော အဆင့်များသာ ကျန်တော့မှာပါ။ <code>Trainer.train()</code> ကို run ဖို့ ပတ်ဝန်းကျင်ကို ပြင်ဆင်တာက အခက်ခဲဆုံး အပိုင်းဖြစ်နိုင်ပါတယ်၊ ဘာလို့လဲဆိုတော့ ဒါက CPU ပေါ်မှာ အလွန်နှေးကွေးစွာ run မှာဖြစ်လို့ပါ။ သင့်မှာ GPU မရှိဘူးဆိုရင် <a href="https://colab.research.google.com/" rel="nofollow">Google Colab</a> မှာ အခမဲ့ GPUs ဒါမှမဟုတ် TPUs ကို ရယူနိုင်ပါတယ်။</p> <blockquote class="tip" data-svelte-h="svelte-1d3djxy"><p>📚 <strong>Training အရင်းအမြစ်များ</strong>: Training ထဲကို မဝင်ခင်၊ ပြည့်စုံသော <a href="https://huggingface.co/docs/transformers/main/en/training" rel="nofollow">🤗 Transformers training guide</a> ကို လေ့လာပြီး <a href="https://huggingface.co/learn/cookbook/en/fine_tuning_code_llm_on_single_gpu" rel="nofollow">fine-tuning cookbook</a> မှာပါတဲ့ လက်တွေ့ဥပမာတွေကို ရှာဖွေပါ။</p></blockquote> <p data-svelte-h="svelte-7a47qq">အောက်ပါ code ဥပမာတွေက ယခင်အပိုင်းက ဥပမာတွေကို သင်ပြီးသားလို့ ယူဆထားပါတယ်။ သင်လိုအပ်တာတွေကို အကျဉ်းချုပ် ပြန်ဖော်ပြထားပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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
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)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="training" 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" href="#training"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Training</span></h3> <p data-svelte-h="svelte-17bgh6j">ကျွန်တော်တို့ရဲ့ <code>Trainer</code> ကို သတ်မှတ်ခြင်းမပြုမီ ပထမအဆင့်ကတော့ <code>Trainer</code> က training နဲ့ evaluation အတွက် အသုံးပြုမယ့် hyperparameters အားလုံးပါဝင်တဲ့ <code>TrainingArguments</code> class တစ်ခုကို သတ်မှတ်ဖို့ပါပဲ။ သင် ပေးဆောင်ရမယ့် တစ်ခုတည်းသော argument ကတော့ လေ့ကျင့်ပြီးသား model ကို သိမ်းဆည်းမယ့် directory ဖြစ်သလို၊ လမ်းတစ်လျှောက်မှာရှိတဲ့ checkpoints တွေကိုလည်း သိမ်းဆည်းမယ့် directory ပါပဲ။ ကျန်တာတွေအားလုံးအတွက်တော့ default တွေကို ချန်ထားခဲ့နိုင်ပါတယ်၊ ဒါတွေက အခြေခံ fine-tuning အတွက် ကောင်းကောင်းအလုပ်လုပ်ပါလိမ့်မယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments
training_args = TrainingArguments(<span class="hljs-string">&quot;test-trainer&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-6s6xsx">training လုပ်နေစဉ်မှာ သင်ရဲ့ model ကို Hub ကို အလိုအလျောက် upload လုပ်ချင်တယ်ဆိုရင် <code>TrainingArguments</code> မှာ <code>push_to_hub=True</code> ကို ထည့်သွင်းပေးပါ။ ဒီအကြောင်းကို <a href="/course/chapter4/3">Chapter 4</a> မှာ ပိုမိုလေ့လာပါမယ်။</p> <blockquote class="tip" data-svelte-h="svelte-109ph51"><p>🚀 <strong>Advanced Configuration</strong>: ရရှိနိုင်သော training arguments အားလုံးနှင့် optimization strategies များအကြောင်း အသေးစိတ်အချက်အလက်များအတွက် <a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments" rel="nofollow">TrainingArguments documentation</a> နှင့် <a href="https://huggingface.co/learn/cookbook/en/fine_tuning_code_llm_on_single_gpu" rel="nofollow">training configuration cookbook</a> ကို ကြည့်ရှုပါ။</p></blockquote> <p data-svelte-h="svelte-1oki3bg">ဒုတိယအဆင့်ကတော့ ကျွန်တော်တို့ရဲ့ model ကို သတ်မှတ်ဖို့ပါပဲ။ <a href="/course/chapter2">ယခင်အခန်း</a> မှာလိုပဲ၊ label နှစ်ခုပါတဲ့ <code>AutoModelForSequenceClassification</code> class ကို ကျွန်တော်တို့ အသုံးပြုပါမယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-e5qjme">ဒီ pretrained model ကို instantiate လုပ်ပြီးနောက် သတိပေးချက်တစ်ခု ရရှိတာကို သင်သတိပြုမိပါလိမ့်မယ်။ ဒါက BERT ကို sentence pair တွေကို classify လုပ်ဖို့ pretrain လုပ်မထားလို့ပါပဲ၊ ဒါကြောင့် pretrained model ရဲ့ head ကို ဖယ်ရှားပြီး sequence classification အတွက် သင့်လျော်တဲ့ head အသစ်တစ်ခုကို ထည့်သွင်းထားပါတယ်။ သတိပေးချက်တွေက အချို့ weights တွေကို အသုံးမပြုခဲ့ဘူး (ဖယ်ရှားလိုက်တဲ့ pretraining head နဲ့ ကိုက်ညီတဲ့ weights တွေ) နဲ့ အချို့ကိုတော့ ကျပန်း (randomly) initialize လုပ်ခဲ့တယ် (head အသစ်အတွက် weights တွေ) ဆိုတာကို ဖော်ပြပါတယ်။ ဒါက model ကို train လုပ်ဖို့ သင့်ကို အားပေးနေတာဖြစ်ပြီး၊ ဒါဟာ ကျွန်တော်တို့ အခုလုပ်မယ့်အရာပါပဲ။</p> <p data-svelte-h="svelte-11wl0c8">ကျွန်တော်တို့မှာ model ရှိပြီးတာနဲ့၊ အခုအထိ တည်ဆောက်ခဲ့တဲ့ objects အားလုံးကို <code>model</code><code>training_args</code>၊ training နဲ့ validation datasets တွေ၊ ကျွန်တော်တို့ရဲ့ <code>data_collator</code> နဲ့ ကျွန်တော်တို့ရဲ့ <code>processing_class</code> တွေကို ပေးပို့ခြင်းဖြင့် <code>Trainer</code> တစ်ခုကို သတ်မှတ်နိုင်ပါပြီ။ <code>processing_class</code> parameter က Trainer ကို processing အတွက် ဘယ် tokenizer ကို အသုံးပြုရမယ်ဆိုတာကို ပြောပြပေးတဲ့ ပိုမိုအသစ်သော ထပ်တိုးမှုတစ်ခုပါ။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer
trainer = Trainer(
model,
training_args,
train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
data_collator=data_collator,
processing_class=tokenizer,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-18nfq4c">သင်က tokenizer တစ်ခုကို <code>processing_class</code> အဖြစ် ပေးပို့တဲ့အခါ၊ <code>Trainer</code> က အသုံးပြုမယ့် default <code>data_collator</code> က <code>DataCollatorWithPadding</code> ဖြစ်ပါလိမ့်မယ်။ ဒီအခြေအနေမှာတော့ သင် <code>data_collator=data_collator</code> လိုင်းကို ချန်လှပ်ထားနိုင်ပါတယ်၊ ဒါပေမယ့် processing pipeline ရဲ့ ဒီအရေးကြီးတဲ့ အစိတ်အပိုင်းကို သင့်ကို ပြသဖို့ ဒီနေရာမှာ ထည့်သွင်းထားပါတယ်။</p> <blockquote class="tip" data-svelte-h="svelte-xbmjaf"><p>📖 <strong>ပိုမိုလေ့လာရန်</strong>: Trainer class နှင့် ၎င်း၏ parameters များအကြောင်း ပြည့်စုံသောအသေးစိတ်အချက်အလက်များအတွက် <a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer" rel="nofollow">Trainer API documentation</a> ကို ကြည့်ရှုပြီး <a href="https://huggingface.co/learn/cookbook/en/fine_tuning_code_llm_on_single_gpu" rel="nofollow">training cookbook recipes</a> တွင် အဆင့်မြင့် အသုံးပြုပုံများကို လေ့လာပါ။</p></blockquote> <p data-svelte-h="svelte-fmjjp3">ကျွန်တော်တို့ရဲ့ dataset ပေါ်မှာ model ကို fine-tune လုပ်ဖို့အတွက်၊ ကျွန်တော်တို့ရဲ့ <code>Trainer</code> ရဲ့ <code>train()</code> method ကို ခေါ်ဆိုရုံပါပဲ-</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->trainer.train()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-sc5mbc">ဒါက fine-tuning ကို စတင်ပါလိမ့်မယ် (GPU ပေါ်မှာ မိနစ်အနည်းငယ် ကြာမြင့်ပါလိမ့်မယ်) ပြီးတော့ training loss ကို step ၅၀၀ တိုင်းမှာ အစီရင်ခံပါလိမ့်မယ်။ ဒါပေမယ့် သင့် model ဘယ်လောက် ကောင်းကောင်း (ဒါမှမဟုတ် ဆိုးဆိုး) အလုပ်လုပ်နေတယ်ဆိုတာကိုတော့ ပြောပြမှာ မဟုတ်ပါဘူး။ ဒါက အောက်ပါအချက်တွေကြောင့်ပါ</p> <ol data-svelte-h="svelte-11jiz4b"><li><code>TrainingArguments</code> မှာ <code>eval_strategy</code> ကို <code>&quot;steps&quot;</code> (eval_steps တိုင်းမှာ evaluate လုပ်ပါ) ဒါမှမဟုတ် <code>&quot;epoch&quot;</code> (epoch တစ်ခုစီရဲ့ အဆုံးမှာ evaluate လုပ်ပါ) အဖြစ် သတ်မှတ်ခြင်းဖြင့် training လုပ်နေစဉ် evaluate လုပ်ဖို့ ကျွန်တော်တို့ <code>Trainer</code> ကို မပြောခဲ့ပါဘူး။</li> <li>အဲဒီ evaluation လုပ်နေစဉ် metric တွက်ချက်ဖို့ <code>compute_metrics()</code> function တစ်ခုကို ကျွန်တော်တို့ <code>Trainer</code> ကို မပေးခဲ့ပါဘူး (မဟုတ်ရင် evaluation က loss ကိုသာ print လုပ်မှာဖြစ်ပြီး၊ ဒါက အလိုလိုနားလည်ရခက်တဲ့ နံပါတ်တစ်ခုပါ)။</li></ol> <h3 class="relative group"><a id="evaluation" 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" href="#evaluation"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Evaluation</span></h3> <p data-svelte-h="svelte-f8qoi0">အသုံးဝင်တဲ့ <code>compute_metrics()</code> function တစ်ခုကို ဘယ်လိုတည်ဆောက်ရမလဲ၊ နောက်တစ်ကြိမ် train လုပ်တဲ့အခါ ဘယ်လိုအသုံးပြုရမလဲဆိုတာ ကြည့်ရအောင်။ function က <code>EvalPrediction</code> object (အမည်ပါတဲ့ tuple တစ်ခုဖြစ်ပြီး <code>predictions</code> field နဲ့ <code>label_ids</code> field တွေ ပါဝင်ပါတယ်) ကို ယူရပါမယ်၊ ပြီးတော့ strings တွေကို floats တွေနဲ့ map လုပ်ထားတဲ့ dictionary တစ်ခုကို ပြန်ပို့ပါလိမ့်မယ် (strings တွေက ပြန်ပို့တဲ့ metrics တွေရဲ့ နာမည်တွေဖြစ်ပြီး၊ floats တွေက ၎င်းတို့ရဲ့ values တွေပါ)။ ကျွန်တော်တို့ရဲ့ model ကနေ predictions တွေရဖို့၊ <code>Trainer.predict()</code> command ကို အသုံးပြုနိုင်ပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->predictions = trainer.predict(tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>])
<span class="hljs-built_in">print</span>(predictions.predictions.shape, predictions.label_ids.shape)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->(<span class="hljs-number">408</span>, <span class="hljs-number">2</span>) (<span class="hljs-number">408</span>,)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-3d9hhy"><code>predict()</code> method ရဲ့ output က <code>predictions</code>, <code>label_ids</code>, နဲ့ <code>metrics</code> ဆိုတဲ့ fields သုံးခုပါတဲ့ အခြားအမည်ပါတဲ့ tuple တစ်ခုပါပဲ။ <code>metrics</code> field ကတော့ ပေးပို့ထားတဲ့ dataset ပေါ်က loss ကိုသာမက အချိန် metrics အချို့ (စုစုပေါင်းနဲ့ ပျမ်းမျှအားဖြင့် ခန့်မှန်းဖို့ ဘယ်လောက်ကြာသလဲ) ကိုလည်း ပါဝင်ပါလိမ့်မယ်။ ကျွန်တော်တို့ <code>compute_metrics()</code> function ကို ဖြည့်စွက်ပြီး <code>Trainer</code> ကို ပေးပို့လိုက်တာနဲ့၊ အဲဒီ field က <code>compute_metrics()</code> ကနေ ပြန်ပို့တဲ့ metrics တွေကိုလည်း ပါဝင်ပါလိမ့်မယ်။</p> <p data-svelte-h="svelte-139laul">သင်တွေ့ရတဲ့အတိုင်း၊ <code>predictions</code> က 408 x 2 shape ရှိတဲ့ two-dimensional array တစ်ခုပါ (408 က ကျွန်တော်တို့ <code>predict()</code> ကို ပေးပို့ခဲ့တဲ့ dataset ထဲက element အရေအတွက်ပါ)။ ဒါတွေက ကျွန်တော်တို့ <code>predict()</code> ကို ပေးပို့ခဲ့တဲ့ dataset ရဲ့ element တစ်ခုစီအတွက် logits တွေပါ (သင် <a href="/course/chapter2">ယခင်အခန်း</a> မှာ တွေ့ခဲ့တဲ့အတိုင်း၊ Transformer model တွေအားလုံးက logits တွေကို ပြန်ပို့ပါတယ်)။ ၎င်းတို့ကို ကျွန်တော်တို့ရဲ့ labels တွေနဲ့ နှိုင်းယှဉ်နိုင်တဲ့ predictions တွေအဖြစ် ပြောင်းလဲဖို့အတွက်၊ ဒုတိယ axis မှာ အများဆုံး value ရှိတဲ့ index ကို ယူဖို့ လိုအပ်ပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
preds = np.argmax(predictions.predictions, axis=-<span class="hljs-number">1</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1x6zswv">အခု ကျွန်တော်တို့ ဒီ <code>preds</code> တွေကို labels တွေနဲ့ နှိုင်းယှဉ်နိုင်ပါပြီ။ ကျွန်တော်တို့ရဲ့ <code>compute_metric()</code> function ကို တည်ဆောက်ဖို့အတွက် 🤗 <a href="https://github.com/huggingface/evaluate/" rel="nofollow">Evaluate</a> library က metrics တွေကို အားကိုးပါမယ်။ <code>evaluate.load()</code> function ကို အသုံးပြုပြီး dataset ကို loading လုပ်သလိုပဲ MRPC dataset နဲ့ သက်ဆိုင်တဲ့ metrics တွေကို အလွယ်တကူ load လုပ်နိုင်ပါတယ်။ ပြန်ပို့တဲ့ object မှာ metric တွက်ချက်မှုကို လုပ်ဆောင်ဖို့ အသုံးပြုနိုင်တဲ့ <code>compute()</code> method တစ်ခု ပါရှိပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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=preds, references=predictions.label_ids)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->{<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>}<!-- HTML_TAG_END --></pre></div> <blockquote data-svelte-h="svelte-qkzhea"><p>[!TIP][🤗 Evaluate documentation](<a href="https://huggingface.co/docs/evaluate/" rel="nofollow">https://huggingface.co/docs/evaluate/</a>) တွင် မတူညီသော evaluation metrics များနှင့် strategies များအကြောင်း လေ့လာပါ။</p></blockquote> <p data-svelte-h="svelte-1oxiuge">သင်ရရှိမယ့် တိကျတဲ့ရလဒ်တွေက မော်ဒယ် head ရဲ့ ကျပန်း (random) initialization ကြောင့် ပြောင်းလဲနိုင်ပါတယ်၊ ဒါပေမယ့် ဒီနေရာမှာ ကျွန်တော်တို့ရဲ့ မော်ဒယ်က validation set မှာ 85.78% accuracy နဲ့ 89.97% F1 score ရရှိတာကို တွေ့ရပါတယ်။ ဒါတွေက GLUE benchmark အတွက် MRPC dataset မှာ ရလဒ်တွေကို အကဲဖြတ်ဖို့ အသုံးပြုတဲ့ metrics နှစ်ခုပါပဲ။ <a href="https://arxiv.org/pdf/1810.04805.pdf" rel="nofollow">BERT paper</a> မှာပါတဲ့ ဇယားက base model အတွက် F1 score 88.9 လို့ ဖော်ပြထားပါတယ်။ ကျွန်တော်တို့ အခု အသုံးပြုနေတာက <code>cased</code> model ဖြစ်ပြီး၊ အဲဒါက ပိုကောင်းတဲ့ရလဒ်ကို ရှင်းပြပါတယ်။</p> <p data-svelte-h="svelte-wlrekv">အားလုံးကို ပေါင်းစပ်လိုက်ရင်၊ ကျွန်တော်တို့ <code>compute_metrics()</code> function ကို ရရှိပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_preds</span>):
metric = evaluate.load(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
logits, labels = eval_preds
predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)
<span class="hljs-keyword">return</span> metric.compute(predictions=predictions, references=labels)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-18iod4s">ပြီးတော့ epoch တစ်ခုစီရဲ့ အဆုံးမှာ metrics တွေ အစီရင်ခံတာကို လက်တွေ့အသုံးပြုတာကို ကြည့်ဖို့အတွက်၊ ဒီ <code>compute_metrics()</code> function နဲ့ <code>Trainer</code> အသစ်တစ်ခုကို ဘယ်လိုသတ်မှတ်ရမလဲဆိုတာ ဤတွင် ဖော်ပြထားပါတယ်-</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->training_args = TrainingArguments(<span class="hljs-string">&quot;test-trainer&quot;</span>, eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
trainer = Trainer(
model,
training_args,
train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
data_collator=data_collator,
processing_class=tokenizer,
compute_metrics=compute_metrics,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-z4wp86">၎င်း၏ <code>eval_strategy</code> ကို <code>&quot;epoch&quot;</code> အဖြစ် သတ်မှတ်ထားသော <code>TrainingArguments</code> အသစ်တစ်ခုနှင့် model အသစ်တစ်ခုကို ဖန်တီးထားတာကို သတိပြုပါ။ မဟုတ်ရင်၊ ကျွန်တော်တို့ အရင်က train ထားပြီးသား model ကိုပဲ ဆက်လက် training လုပ်နေမှာ ဖြစ်ပါတယ်။ training run အသစ်တစ်ခု စတင်ရန်၊ ကျွန်တော်တို့ အောက်ပါအတိုင်း execute လုပ်ပါ။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->trainer.train()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-79n3mn">ဒီတစ်ခါတော့ training loss အပြင် epoch တစ်ခုစီရဲ့ အဆုံးမှာ validation loss နဲ့ metrics တွေကိုပါ အစီရင်ခံပါလိမ့်မယ်။ ထပ်မံပြောရရင်၊ model ရဲ့ random head initialization ကြောင့် သင်ရရှိမယ့် တိကျတဲ့ accuracy/F1 score က ကျွန်တော်တို့ ရှာဖွေတွေ့ရှိတာနဲ့ အနည်းငယ် ကွာခြားနိုင်ပေမယ့်၊ အနီးစပ်ဆုံး တူညီသင့်ပါတယ်။</p> <h3 class="relative group"><a id="advanced-training-features" 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" href="#advanced-training-features"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Advanced Training Features</span></h3> <p data-svelte-h="svelte-1sj46a0"><code>Trainer</code> မှာ ခေတ်မီ deep learning အကောင်းဆုံးနည်းလမ်းတွေကို လက်လှမ်းမီစေတဲ့ built-in features များစွာ ပါဝင်ပါတယ်-</p> <p data-svelte-h="svelte-29d5qu"><strong>Mixed Precision Training</strong>: ပိုမိုမြန်ဆန်သော training နှင့် memory အသုံးပြုမှု လျှော့ချရန်အတွက် သင်၏ training arguments တွင် <code>fp16=True</code> ကို အသုံးပြုပါ။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->training_args = TrainingArguments(
<span class="hljs-string">&quot;test-trainer&quot;</span>,
eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
fp16=<span class="hljs-literal">True</span>, <span class="hljs-comment"># Mixed precision ကို ဖွင့်ပါ</span>
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-6ppptw"><strong>Gradient Accumulation</strong>: GPU memory နည်းပါးတဲ့အခါ ပိုကြီးမားတဲ့ batch sizes တွေကို ထိထိရောက်ရောက် အသုံးပြုနိုင်ဖို့-</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->training_args = TrainingArguments(
<span class="hljs-string">&quot;test-trainer&quot;</span>,
eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
per_device_train_batch_size=<span class="hljs-number">4</span>,
gradient_accumulation_steps=<span class="hljs-number">4</span>, <span class="hljs-comment"># ထိရောက်သော batch size = 4 * 4 = 16</span>
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-r3udgc"><strong>Learning Rate Scheduling</strong>: Trainer က default အားဖြင့် linear decay ကို အသုံးပြုပါတယ်၊ ဒါပေမယ့် ဒါကို သင် စိတ်ကြိုက်ပြင်ဆင်နိုင်ပါတယ်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->training_args = TrainingArguments(
<span class="hljs-string">&quot;test-trainer&quot;</span>,
eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
learning_rate=<span class="hljs-number">2e-5</span>,
lr_scheduler_type=<span class="hljs-string">&quot;cosine&quot;</span>, <span class="hljs-comment"># မတူညီသော schedulers များကို စမ်းသပ်ကြည့်ပါ</span>
)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1xgai0a"><p>🎯 <strong>စွမ်းဆောင်ရည် မြှင့်တင်ရေး</strong>: distributed training၊ memory optimization နှင့် hardware-specific optimizations အပါအဝင် ပိုမိုအဆင့်မြင့်သော training နည်းလမ်းများအတွက် <a href="https://huggingface.co/docs/transformers/main/en/performance" rel="nofollow">🤗 Transformers performance guide</a> ကို လေ့လာပါ။</p></blockquote> <p data-svelte-h="svelte-14w3rbe"><code>Trainer</code> က GPUs များစွာ ဒါမှမဟုတ် TPUs တွေပေါ်မှာ အလိုအလျောက် အလုပ်လုပ်နိုင်ပြီး distributed training အတွက် options များစွာကို ပေးစွမ်းပါတယ်။ ဒါတွေအားလုံးကို Chapter 10 မှာ ကျွန်တော်တို့ ဆွေးနွေးသွားပါမယ်။</p> <p data-svelte-h="svelte-1dp7zr8">ဒါက <code>Trainer</code> API ကို အသုံးပြုပြီး fine-tuning လုပ်ခြင်းနိဒါန်းကို နိဂုံးချုပ်လိုက်ပါပြီ။ အဖြစ်များဆုံး NLP လုပ်ငန်းအများစုအတွက် ဒါကို ဘယ်လိုလုပ်ဆောင်ရမယ်ဆိုတဲ့ ဥပမာတစ်ခုကို <a href="/course/chapter7">Chapter 7</a> မှာ ပေးထားပါလိမ့်မယ်၊ ဒါပေမယ့် အခုတော့ pure PyTorch training loop နဲ့ ဒီအရာတွေကို ဘယ်လိုလုပ်ဆောင်ရမလဲဆိုတာ ကြည့်ရအောင်။</p> <blockquote class="tip" data-svelte-h="svelte-zubhm1"><p>📝 <strong>ဥပမာများ ထပ်မံကြည့်ရှုရန်</strong>: ပြည့်စုံသော <a href="https://huggingface.co/docs/transformers/main/en/notebooks" rel="nofollow">🤗 Transformers notebooks</a> စုစည်းမှုကို ကြည့်ရှုပါ။</p></blockquote> <h2 class="relative group"><a id="section-quiz" 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" href="#section-quiz"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း</span></h2> <p data-svelte-h="svelte-1e3hmxk">Trainer API နှင့် fine-tuning concepts များအကြောင်း သင့်နားလည်မှုကို စမ်းသပ်ပါ။</p> <h3 class="relative group"><a id="1-trainer-မပတ-processingclass-parameter-ရ-ရညရယခကက-ဘလ" 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" href="#1-trainer-မပတ-processingclass-parameter-ရ-ရညရယခကက-ဘလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>1. Trainer မှာပါတဲ့ processing_class parameter ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->၎င်းသည် မည်သည့် model architecture ကို အသုံးပြုရမည်ကို သတ်မှတ်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->၎င်းသည် ဒေတာများကို စီမံဆောင်ရွက်ရန် မည်သည့် tokenizer ကို အသုံးပြုရမည်ကို Trainer ကို ပြောပြသည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->၎င်းသည် training အတွက် batch size ကို ဆုံးဖြတ်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->၎င်းသည် evaluation frequency ကို ထိန်းချုပ်သည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="2-trainingarguments-parameter-က-training-လပနစဉ-evaluation-က-ဘယလကကက-လပရမယဆတက-ဘယလထနခပသလ" 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" href="#2-trainingarguments-parameter-က-training-လပနစဉ-evaluation-က-ဘယလကကက-လပရမယဆတက-ဘယလထနခပသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2. TrainingArguments parameter က training လုပ်နေစဉ် evaluation ကို ဘယ်လောက်ကြာကြာ လုပ်ရမယ်ဆိုတာကို ဘယ်လိုထိန်းချုပ်သလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->eval_frequency<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->eval_strategy<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->evaluation_steps<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->do_eval<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="3-trainingarguments-မ-fp16true-က-ဘက-ဖငပသလ" 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" href="#3-trainingarguments-မ-fp16true-က-ဘက-ဖငပသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>3. TrainingArguments မှာ fp16=True က ဘာကို ဖွင့်ပေးသလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->ပိုမိုမြန်ဆန်သော training အတွက် 16-bit integer precision။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->ပိုမိုမြန်ဆန်သော training နှင့် memory အသုံးပြုမှု လျှော့ချရန်အတွက် 16-bit floating-point numbers ဖြင့် mixed precision training။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->အတိအကျ 16 epochs အတွက် training လုပ်ခြင်း။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->distributed training အတွက် GPUs ၁၆ ခု အသုံးပြုခြင်း။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="4-trainer-မပတ-computemetrics-function-ရ-အခနကဏဍက-ဘလ" 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" href="#4-trainer-မပတ-computemetrics-function-ရ-အခနကဏဍက-ဘလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>4. Trainer မှာပါတဲ့ compute_metrics function ရဲ့ အခန်းကဏ္ဍက ဘာလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->၎င်းသည် training လုပ်နေစဉ် loss ကို တွက်ချက်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->၎င်းသည် logits များကို predictions များအဖြစ် ပြောင်းလဲပြီး accuracy နှင့် F1 ကဲ့သို့သော evaluation metrics များကို တွက်ချက်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->၎င်းသည် မည်သည့် optimizer ကို အသုံးပြုရမည်ကို ဆုံးဖြတ်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->၎င်းသည် training data ကို preprocessing လုပ်သည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="5-trainer-က-evaldataset-မပတအခ-ဘဖစမလ" 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" href="#5-trainer-က-evaldataset-မပတအခ-ဘဖစမလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>5. Trainer ကို eval_dataset မပေးတဲ့အခါ ဘာဖြစ်မလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->Training က error နဲ့ fail ဖြစ်သွားပါလိမ့်မယ်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->Trainer က training data ကို evaluation အတွက် အလိုအလျောက် ခွဲထုတ်ပါလိမ့်မယ်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->Training လုပ်နေစဉ် evaluation metrics တွေ မရရှိနိုင်ပေမယ့် training ကတော့ အလုပ်လုပ်နေပါလိမ့်မယ်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->Model က training data ကို evaluation အတွက် အသုံးပြုပါလိမ့်မယ်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="6-gradient-accumulation-ဆတ-ဘလ-ဘယလ-ဖငရမလ" 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" href="#6-gradient-accumulation-ဆတ-ဘလ-ဘယလ-ဖငရမလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>6. Gradient accumulation ဆိုတာ ဘာလဲ၊ ဘယ်လို ဖွင့်ရမလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->၎င်းသည် gradients များကို disk ထဲသို့ သိမ်းဆည်းခြင်းဖြစ်ပြီး save_gradients=True ဖြင့် ဖွင့်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->၎င်းသည် updating မလုပ်မီ batches အများအပြားပေါ်မှာ gradients များကို စုဆောင်းခြင်းဖြစ်ပြီး gradient_accumulation_steps ဖြင့် ဖွင့်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->၎င်းသည် gradient တွက်ချက်မှုကို အရှိန်မြှင့်ပေးပြီး fp16 ဖြင့် အလိုအလျောက် ဖွင့်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->၎င်းသည် gradient overflow ကို ကာကွယ်ပေးပြီး gradient_clipping=True ဖြင့် ဖွင့်သည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <blockquote class="tip" data-svelte-h="svelte-1kcsdg"><p>💡 <strong>အဓိက အချက်များ:</strong></p> <ul><li><code>Trainer</code> API သည် training ၏ ရှုပ်ထွေးမှုအများစုကို ကိုင်တွယ်ပေးသည့် အဆင့်မြင့် interface တစ်ခုဖြစ်သည်။</li> <li>သင့်ဒေတာကို မှန်ကန်စွာ ကိုင်တွယ်ရန် <code>processing_class</code> ကို အသုံးပြု၍ tokenizer ကို သတ်မှတ်ပါ။</li> <li><code>TrainingArguments</code> သည် training ၏ ကဏ္ဍအားလုံးကို ထိန်းချုပ်သည်- learning rate, batch size, evaluation strategy နှင့် optimizations များ။</li> <li><code>compute_metrics</code> သည် training loss အပြင် စိတ်ကြိုက် evaluation metrics များကို ဖွင့်ပေးသည်။</li> <li>Mixed precision (<code>fp16=True</code>) နှင့် gradient accumulation ကဲ့သို့သော ခေတ်မီ features များသည် training ထိရောက်မှုကို သိသိသာသာ တိုးတက်စေနိုင်သည်။</li></ul></blockquote> <h2 class="relative group"><a id="ဝဟရ-ရငလငခက-glossary" 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" href="#ဝဟရ-ရငလငခက-glossary"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ဝေါဟာရ ရှင်းလင်းချက် (Glossary)</span></h2> <ul data-svelte-h="svelte-yy2yyf"><li><strong>Fine-tuning</strong>: ကြိုတင်လေ့ကျင့်ထားပြီးသား (pre-trained) မော်ဒယ်တစ်ခုကို သီးခြားလုပ်ငန်းတစ်ခု (specific task) အတွက် အနည်းငယ်သော ဒေတာနဲ့ ထပ်မံလေ့ကျင့်ပေးခြင်းကို ဆိုလိုပါတယ်။</li> <li><strong>Trainer API</strong>: Hugging Face Transformers library မှ model များကို ထိရောက်စွာ လေ့ကျင့်ရန်အတွက် ဒီဇိုင်းထုတ်ထားသော မြင့်မားသောအဆင့် (high-level) API (Application Programming Interface)။</li> <li><strong>Pretrained Models</strong>: အကြီးစား ဒေတာအမြောက်အမြားဖြင့် ကြိုတင်လေ့ကျင့်ထားပြီးဖြစ်သော AI (Artificial Intelligence) မော်ဒယ်များ။</li> <li><strong>Dataset</strong>: AI မော်ဒယ်တွေ လေ့ကျင့်ဖို့အတွက် အသုံးပြုတဲ့ ဒေတာအစုအဝေးတစ်ခုပါ။</li> <li><strong>Preprocessing</strong>: ဒေတာများကို model က နားလည်ပြီး လုပ်ဆောင်နိုင်တဲ့ ပုံစံအဖြစ် ပြောင်းလဲပြင်ဆင်ခြင်း လုပ်ငန်းစဉ်။</li> <li><strong>GPU (Graphics Processing Unit)</strong>: ဂရပ်ဖစ်လုပ်ဆောင်မှုအတွက် အထူးဒီဇိုင်းထုတ်ထားသော processor တစ်မျိုးဖြစ်သော်လည်း AI/ML (Artificial Intelligence/Machine Learning) လုပ်ငန်းများတွင် အရှိန်မြှင့်ရန် အသုံးများသည်။</li> <li><strong>CPU (Central Processing Unit)</strong>: ကွန်ပျူတာ၏ ပင်မ processor ဖြစ်ပြီး အထွေထွေလုပ်ငန်းများကို လုပ်ဆောင်သည်။</li> <li><strong>TPU (Tensor Processing Unit)</strong>: Google မှ AI/ML (Artificial Intelligence/Machine Learning) workloads များအတွက် အထူးဒီဇိုင်းထုတ်ထားသော processor တစ်မျိုး။</li> <li><strong>Google Colab</strong>: Google မှ ပံ့ပိုးပေးထားသော cloud-based Jupyter Notebook environment တစ်ခုဖြစ်ပြီး Python code များကို web browser မှတစ်ဆင့် run နိုင်စေသည်။ အခမဲ့ GPU/TPU အသုံးပြုခွင့်ပေးသည်။</li> <li><strong><code>datasets</code> (Library)</strong>: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး AI မော်ဒယ်တွေ လေ့ကျင့်ဖို့အတွက် ဒေတာအစုအဝေး (datasets) တွေကို လွယ်လွယ်ကူကူ ဝင်ရောက်ရယူ၊ စီမံခန့်ခွဲပြီး အသုံးပြုနိုင်စေပါတယ်။</li> <li><strong><code>transformers</code> (Library)</strong>: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး Transformer မော်ဒယ်တွေကို အသုံးပြုပြီး Natural Language Processing (NLP), computer vision, audio processing စတဲ့ နယ်ပယ်တွေမှာ အဆင့်မြင့် AI မော်ဒယ်တွေကို တည်ဆောက်ပြီး အသုံးပြုနိုင်စေပါတယ်။</li> <li><strong><code>AutoTokenizer</code></strong>: Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တစ်ခုဖြစ်ပြီး မော်ဒယ်အမည်ကို အသုံးပြုပြီး သက်ဆိုင်ရာ tokenizer ကို အလိုအလျောက် load လုပ်ပေးသည်။</li> <li><strong><code>DataCollatorWithPadding</code></strong>: Hugging Face Transformers library မှ ပံ့ပိုးပေးသော class တစ်ခုဖြစ်ပြီး dynamic padding ကို အသုံးပြု၍ batch တစ်ခုအတွင်း samples များကို စုစည်းပေးသည်။</li> <li><strong><code>load_dataset()</code> Function</strong>: Hugging Face Datasets library မှ dataset များကို download လုပ်ပြီး cache လုပ်ရန် အသုံးပြုသော function။</li> <li><strong>Checkpoint</strong>: မော်ဒယ်၏ weights များနှင့် အခြားဖွဲ့စည်းပုံများ (configuration) ကို သတ်မှတ်ထားသော အချိန်တစ်ခုတွင် သိမ်းဆည်းထားခြင်း။</li> <li><strong><code>tokenize_function()</code></strong>: စာသားများကို tokens အဖြစ် ပြောင်းလဲပေးသည့် function။</li> <li><strong><code>raw_datasets</code></strong>: Preprocessing မလုပ်ရသေးသော dataset များ ပါဝင်သော object။</li> <li><strong><code>tokenized_datasets</code></strong>: Tokenization ပြုလုပ်ပြီးသော dataset များ ပါဝင်သော object။</li> <li><strong><code>batched=True</code></strong>: <code>map()</code> method တွင် အသုံးပြုသော argument တစ်ခုဖြစ်ပြီး function ကို dataset ၏ element အများအပြားပေါ်တွင် တစ်ပြိုင်နက်တည်း အသုံးပြုစေသည်။</li> <li><strong>Hyperparameters</strong>: AI မော်ဒယ်တစ်ခုကို လေ့ကျင့်ရာတွင် အသုံးပြုသူက သတ်မှတ်ပေးရသော parameters များ (ဥပမာ- learning rate, batch size)။</li> <li><strong>TrainingArguments Class</strong>: Trainer ကို အသုံးပြု၍ မော်ဒယ်လေ့ကျင့်ရာတွင် လိုအပ်သော hyperparameters များနှင့် အခြားအခြေအနေများကို သတ်မှတ်ရန် အသုံးပြုသည့် class။</li> <li><strong>Evaluation</strong>: မော်ဒယ်၏ စွမ်းဆောင်ရည်ကို တိုင်းတာခြင်း။</li> <li><strong><code>test-trainer</code></strong>: လေ့ကျင့်ပြီးသား model နှင့် checkpoints များကို သိမ်းဆည်းမည့် directory အမည်။</li> <li><strong><code>push_to_hub=True</code></strong>: training လုပ်နေစဉ် model ကို Hugging Face Hub သို့ အလိုအလျောက် upload လုပ်ရန် သတ်မှတ်သော argument။</li> <li><strong>Hugging Face Hub</strong>: AI မော်ဒယ်တွေ၊ datasets တွေနဲ့ demo တွေကို အခြားသူတွေနဲ့ မျှဝေဖို့၊ ရှာဖွေဖို့နဲ့ ပြန်လည်အသုံးပြုဖို့အတွက် အွန်လိုင်း platform တစ်ခု ဖြစ်ပါတယ်။</li> <li><strong><code>AutoModelForSequenceClassification</code> Class</strong>: Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တစ်ခုဖြစ်ပြီး sequence classification အတွက် pre-trained model ကို အလိုအလျောက် load လုပ်ပေးသည်။</li> <li><strong><code>num_labels</code></strong>: Classification လုပ်ငန်းအတွက် label (အမျိုးအစား) အရေအတွက်။</li> <li><strong>Head (Model Head)</strong>: Transformer မော်ဒယ်၏ အဓိကကိုယ်ထည် (body) အပေါ်တွင် ထည့်သွင်းထားသော အပိုအစိတ်အပိုင်း (layer တစ်ခု သို့မဟုတ် နှစ်ခု) ဖြစ်ပြီး သီးခြားလုပ်ငန်း (task) တစ်ခုအတွက် မော်ဒယ်၏ output များကို ချိန်ညှိပေးသည်။ ဥပမာ- sequence classification အတွက် head သည် logits ကို ထုတ်ပေးသည်။</li> <li><strong>Randomly Initialized</strong>: မော်ဒယ်၏ parameters (weights) များကို စတင်ချိန်တွင် ကျပန်းတန်ဖိုးများ ပေးခြင်း။</li> <li><strong><code>Trainer</code> Class</strong>: 🤗 Transformers library မှ model များကို လေ့ကျင့်ရန်နှင့် အကဲဖြတ်ရန်အတွက် အသုံးပြုသော class။</li> <li><strong><code>train_dataset</code></strong>: Trainer ကို ပေးအပ်သော training set။</li> <li><strong><code>eval_dataset</code></strong>: Trainer ကို ပေးအပ်သော validation set။</li> <li><strong><code>data_collator</code></strong>: batch တစ်ခုအတွင်း samples များကို စုစည်းပေးသော function။</li> <li><strong><code>processing_class</code></strong>: Trainer ကို ဒေတာ processing အတွက် မည်သည့် tokenizer ကို အသုံးပြုရမည်ကို ပြောပြပေးသော parameter။</li> <li><strong><code>trainer.train()</code> Method</strong>: Model ကို fine-tune လုပ်ရန် Trainer class ၏ method။</li> <li><strong>Training Loss</strong>: Training လုပ်နေစဉ် model ၏ ခန့်မှန်းချက်များနှင့် အမှန်တကယ် labels များကြား ကွာခြားမှုကို တိုင်းတာသော တန်ဖိုး။</li> <li><strong><code>eval_strategy</code></strong>: TrainingArguments တွင် evaluation လုပ်ဆောင်မည့် အချိန်နှင့် ကြိမ်နှုန်းကို သတ်မှတ်သော parameter (ဥပမာ- <code>&quot;epoch&quot;</code> သို့မဟုတ် <code>&quot;steps&quot;</code>)။</li> <li><strong><code>eval_steps</code></strong>: evaluation လုပ်ငန်းကို ပြန်လုပ်မည့် training steps အရေအတွက်။</li> <li><strong><code>epoch</code></strong>: dataset တစ်ခုလုံးကို model တစ်ခုက အစအဆုံး တစ်ကြိမ် လေ့ကျင့်မှု ပြီးဆုံးခြင်း။</li> <li><strong><code>compute_metrics()</code> Function</strong>: evaluation လုပ်ငန်းစဉ်အတွင်း metrics (ဥပမာ- accuracy, F1 score) များကို တွက်ချက်ရန်အတွက် Trainer ကို ပေးအပ်သော function။</li> <li><strong><code>Trainer.predict()</code> Method</strong>: Trainer class ၏ method ဖြစ်ပြီး dataset တစ်ခုပေါ်တွင် model ၏ predictions များကို ရရှိစေသည်။</li> <li><strong><code>EvalPrediction</code> Object</strong>: <code>Trainer.predict()</code> မှ ပြန်ပို့သော named tuple တစ်ခုဖြစ်ပြီး <code>predictions</code> field နှင့် <code>label_ids</code> field များကို ပါဝင်သည်။</li> <li><strong><code>predictions</code> Field</strong>: <code>EvalPrediction</code> object တွင် မော်ဒယ်၏ ခန့်မှန်းချက်များ ပါဝင်သော field။</li> <li><strong><code>label_ids</code> Field</strong>: <code>EvalPrediction</code> object တွင် အမှန်တကယ် label ID များ ပါဝင်သော field။</li> <li><strong><code>metrics</code> Field</strong>: <code>EvalPrediction</code> object တွင် တွက်ချက်ထားသော evaluation metrics များ ပါဝင်သော field။</li> <li><strong>Validation Loss</strong>: Validation set ပေါ်တွင် model ၏ ခန့်မှန်းချက်များနှင့် အမှန်တကယ် labels များကြား ကွာခြားမှုကို တိုင်းတာသော တန်ဖိုး။</li> <li><strong>Logits</strong>: မော်ဒယ်၏ နောက်ဆုံး layer မှ ထုတ်ပေးသော raw, unnormalized scores များ။ ၎င်းတို့ကို SoftMax function ကဲ့သို့သော activation function တစ်ခုဖြင့် probabilistic values များအဖြစ် ပြောင်းလဲနိုင်သည်။</li> <li><strong><code>numpy</code> (np)</strong>: Python အတွက် ကိန်းဂဏန်းတွက်ချက်မှုများ ပြုလုပ်ရန် အသုံးပြုသော library။</li> <li><strong><code>np.argmax()</code></strong>: NumPy function တစ်ခုဖြစ်ပြီး array တစ်ခု၏ သတ်မှတ်ထားသော axis ပေါ်ရှိ အများဆုံးတန်ဖိုး၏ index ကို ပြန်ပေးသည်။</li> <li><strong>🤗 Evaluate Library</strong>: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး machine learning မော်ဒယ်တွေရဲ့ စွမ်းဆောင်ရည်ကို တိုင်းတာဖို့အတွက် metrics မျိုးစုံကို ထောက်ပံ့ပေးသည်။</li> <li><strong><code>evaluate.load()</code> Function</strong>: 🤗 Evaluate library မှ evaluation metric တစ်ခုကို load လုပ်ရန် အသုံးပြုသော function။</li> <li><strong><code>metric.compute()</code> Method</strong>: Load လုပ်ထားသော metric object ၏ method ဖြစ်ပြီး predictions နှင့် references (အမှန်တကယ် labels) များကို အသုံးပြု၍ metric value ကို တွက်ချက်သည်။</li> <li><strong>Accuracy</strong>: မှန်ကန်စွာ ခန့်မှန်းနိုင်သော samples ရာခိုင်နှုန်းကို တိုင်းတာသော metric။</li> <li><strong>F1 Score</strong>: Precision (တိကျမှု) နှင့် Recall (ပြန်လည်သိမ်းဆည်းမှု) တို့၏ harmonic mean ကို တွက်ချက်သော metric။<ul><li><strong>Precision</strong>: model မှ အပြုသဘောဟု ခန့်မှန်းခဲ့သော samples များအနက် တကယ့်တကယ် အပြုသဘောဖြစ်သော samples များ၏ အချိုး။</li> <li><strong>Recall</strong>: တကယ့်တကယ် အပြုသဘောဖြစ်သော samples များအနက် model မှ မှန်ကန်စွာ အပြုသဘောဟု ခန့်မှန်းခဲ့သော samples များ၏ အချိုး။</li> <li><strong>Harmonic Mean</strong>: ဂဏန်းအစုအဝေးတစ်ခု၏ အပြန်အလှန်တန်ဖိုးများ၏ ပျမ်းမျှကို တွက်ချက်ခြင်း။</li></ul></li> <li><strong>Random Initialization</strong>: မော်ဒယ်၏ weights များကို စတင်ချိန်တွင် ကျပန်းတန်ဖိုးများ ပေးခြင်း။</li> <li><strong>Validation Loss</strong>: Model ကို လေ့ကျင့်နေစဉ် validation set ပေါ်တွင် တွက်ချက်သော loss။</li> <li><strong>Mixed Precision Training</strong>: မော်ဒယ်ကို လေ့ကျင့်ရာတွင် 16-bit floating-point numbers (fp16) နှင့် 32-bit floating-point numbers (fp32) နှစ်မျိုးလုံးကို ရောစပ်အသုံးပြုခြင်း။ ၎င်းသည် training ကို မြန်ဆန်စေပြီး memory အသုံးပြုမှုကို လျှော့ချသည်။</li> <li><strong><code>fp16=True</code></strong>: Mixed precision training ကို ဖွင့်ရန် TrainingArguments တွင် သတ်မှတ်သော parameter။</li> <li><strong>Gradient Accumulation</strong>: GPU memory ကန့်သတ်ချက်ရှိသောအခါ ပိုကြီးမားသော batch sizes များကို အတုယူရန် batches အများအပြားပေါ်တွင် gradients များကို စုဆောင်းပြီးမှ update လုပ်ခြင်း။</li> <li><strong><code>per_device_train_batch_size</code></strong>: device တစ်ခုစီ (ဥပမာ- GPU တစ်ခုစီ) အတွက် training batch size။</li> <li><strong><code>gradient_accumulation_steps</code></strong>: Gradient များကို update မလုပ်မီ စုဆောင်းမည့် steps အရေအတွက်။</li> <li><strong>Learning Rate Scheduling</strong>: Training လုပ်နေစဉ် learning rate ကို အချိန်ကြာလာသည်နှင့်အမျှ ပြောင်းလဲသွားစေရန် နည်းလမ်း။</li> <li><strong>Linear Decay</strong>: Learning rate ကို အချိန်ကြာလာသည်နှင့်အမျှ လိုင်းဖြောင့်အတိုင်း (linearly) လျှော့ချသွားသော scheduling နည်းလမ်း။</li> <li><strong><code>learning_rate</code></strong>: Training လုပ်နေစဉ် model ၏ weights များကို update လုပ်ရာတွင် အသုံးပြုသော step size။</li> <li><strong><code>lr_scheduler_type=&quot;cosine&quot;</code></strong>: Cosine decay ကဲ့သို့သော learning rate scheduler အမျိုးအစားကို သတ်မှတ်ခြင်း။</li> <li><strong>Distributed Training</strong>: Model တစ်ခုကို ကွန်ပျူတာများစွာ သို့မဟုတ် devices များစွာပေါ်တွင် တစ်ပြိုင်နက်တည်း လေ့ကျင့်ခြင်း။</li> <li><strong>Pure PyTorch Training Loop</strong>: Trainer API ကို အသုံးမပြုဘဲ PyTorch library ၏ အခြေခံလုပ်ဆောင်ချက်များဖြင့် model ကို လေ့ကျင့်ရန် code ကို ကိုယ်တိုင်ရေးသားခြင်း။</li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/course/blob/main/chapters/my/chapter3/3.mdx" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_tyugt6 = {
assets: "/docs/course/pr_1114/my",
base: "/docs/course/pr_1114/my",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/course/pr_1114/my/_app/immutable/entry/start.14794ee9.js"),
import("/docs/course/pr_1114/my/_app/immutable/entry/app.a133f5c6.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 25],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
109 kB
·
Xet hash:
f271aa3e0812039d1b7dd17163d6e111d9e7b2304a4f005aa6a18782ad5e2800

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.