Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"အနှစ်ချုပ်ဖော်ပြခြင်း (Summarization)","local":"summarization","sections":[{"title":"Multilingual Corpus တစ်ခုကို ပြင်ဆင်ခြင်း","local":"preparing-a-multilingual-corpus","sections":[],"depth":2},{"title":"Text Summarization အတွက် Models များ","local":"models-for-text-summarization","sections":[],"depth":2},{"title":"Data များကို Preprocessing လုပ်ခြင်း","local":"preprocessing-the-data","sections":[],"depth":2},{"title":"Text Summarization အတွက် Metrics များ","local":"metrics-for-text-summarization","sections":[{"title":"Strong Baseline တစ်ခုကို ဖန်တီးခြင်း","local":"creating-a-strong-baseline","sections":[],"depth":3}],"depth":2},{"title":"Trainer API ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-the-trainer-api","sections":[],"depth":2},{"title":"Keras ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-keras","sections":[],"depth":2},{"title":"🤗 Accelerate ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-accelerate","sections":[{"title":"Training အတွက် အရာအားလုံးကို ပြင်ဆင်ခြင်း","local":"preparing-everything-for-training","sections":[],"depth":3},{"title":"Training Loop","local":"training-loop","sections":[],"depth":3}],"depth":2},{"title":"သင် Fine-tuned လုပ်ထားသော Model ကို အသုံးပြုခြင်း","local":"using-your-fine-tuned-model","sections":[],"depth":2},{"title":"ဝေါဟာရ ရှင်းလင်းချက် (Glossary)","local":"ဝဟရ-ရငလငခက-glossary","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/course/pr_1095/my/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/entry/start.8e25cab6.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/scheduler.893fe8c9.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/singletons.ba455c5c.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/index.bce52c8a.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/paths.9a7be869.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/entry/app.b12ce275.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/preload-helper.b5ee8f74.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/index.b1df2166.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/nodes/0.77c840e7.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/nodes/81.fed4b82a.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.e6d31e72.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/Youtube.ec5d7916.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/CodeBlock.abb4f40e.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/CourseFloatingBanner.c1c08878.js"> | |
| <link rel="modulepreload" href="/docs/course/pr_1095/my/_app/immutable/chunks/FrameworkSwitchCourse.4480e339.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"အနှစ်ချုပ်ဖော်ပြခြင်း (Summarization)","local":"summarization","sections":[{"title":"Multilingual Corpus တစ်ခုကို ပြင်ဆင်ခြင်း","local":"preparing-a-multilingual-corpus","sections":[],"depth":2},{"title":"Text Summarization အတွက် Models များ","local":"models-for-text-summarization","sections":[],"depth":2},{"title":"Data များကို Preprocessing လုပ်ခြင်း","local":"preprocessing-the-data","sections":[],"depth":2},{"title":"Text Summarization အတွက် Metrics များ","local":"metrics-for-text-summarization","sections":[{"title":"Strong Baseline တစ်ခုကို ဖန်တီးခြင်း","local":"creating-a-strong-baseline","sections":[],"depth":3}],"depth":2},{"title":"Trainer API ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-the-trainer-api","sections":[],"depth":2},{"title":"Keras ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-keras","sections":[],"depth":2},{"title":"🤗 Accelerate ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း","local":"fine-tuning-mt5-with-accelerate","sections":[{"title":"Training အတွက် အရာအားလုံးကို ပြင်ဆင်ခြင်း","local":"preparing-everything-for-training","sections":[],"depth":3},{"title":"Training Loop","local":"training-loop","sections":[],"depth":3}],"depth":2},{"title":"သင် Fine-tuned လုပ်ထားသော Model ကို အသုံးပြုခြင်း","local":"using-your-fine-tuned-model","sections":[],"depth":2},{"title":"ဝေါဟာရ ရှင်းလင်းချက် (Glossary)","local":"ဝဟရ-ရငလငခက-glossary","sections":[],"depth":2}],"depth":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="summarization" 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="#summarization"><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>အနှစ်ချုပ်ဖော်ပြခြင်း (Summarization)</span></h1> <div class="flex space-x-1 absolute z-10 right-0 top-0" style=""><a href="https://discuss.huggingface.co/t/chapter-7-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/chapter7/section5_pt.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/chapter7/section5_pt.ipynb" target="_blank"><img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"></a></div> <p data-svelte-h="svelte-1i1xhr1">ဒီအပိုင်းမှာ Transformer models တွေကို ရှည်လျားတဲ့ document တွေကို အနှစ်ချုပ်အဖြစ် condensing (သိပ်သည်းအောင် ချုံ့) လုပ်ရာမှာ ဘယ်လိုအသုံးပြုနိုင်လဲဆိုတာ ကြည့်သွားပါမယ်။ ဒီလုပ်ငန်းကို <em>text summarization</em> လို့ သိကြပါတယ်။ ဒါက NLP tasks တွေထဲမှာ အခက်ခဲဆုံးတစ်ခုပါ၊ ဘာလို့လဲဆိုတော့ ရှည်လျားတဲ့ စာပိုဒ်တွေကို နားလည်ခြင်းနဲ့ document တစ်ခုရဲ့ အဓိက ခေါင်းစဉ်တွေကို ဖော်ပြတဲ့ ကိုက်ညီတဲ့ စာသားကို ထုတ်လုပ်ခြင်းလို စွမ်းရည်မျိုးစုံ လိုအပ်လို့ပါပဲ။ သို့သော်လည်း၊ ကောင်းကောင်းလုပ်ဆောင်နိုင်ရင် text summarization ဟာ domain expert တွေရဲ့ ရှည်လျားတဲ့ document တွေကို အသေးစိတ်ဖတ်ရမယ့် ဝန်ထုပ်ဝန်ပိုးကို လျှော့ချခြင်းဖြင့် လုပ်ငန်းလုပ်ဆောင်မှု အမျိုးမျိုးကို အရှိန်မြှင့်တင်ပေးနိုင်တဲ့ အစွမ်းထက်တဲ့ ကိရိယာတစ်ခု ဖြစ်ပါတယ်။</p> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/yHnr5Dk2zCI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-htdrdl"><a href="https://huggingface.co/models?pipeline_tag=summarization&sort=downloads" rel="nofollow">Hugging Face Hub</a> ပေါ်မှာ summarization အတွက် fine-tuned models အမျိုးမျိုး ရှိနေပေမယ့်၊ ဒီ models တွေအားလုံးနီးပါးဟာ English documents တွေအတွက်ပဲ သင့်လျော်ပါတယ်။ ဒါကြောင့်၊ ဒီအပိုင်းမှာ ဆန်းသစ်မှုတစ်ခုအနေနဲ့၊ English နဲ့ Spanish အတွက် bilingual model တစ်ခုကို ကျွန်တော်တို့ train လုပ်ပါမယ်။ ဒီအပိုင်းရဲ့ အဆုံးမှာ၊ ဒီနေရာမှာ ပြသထားတဲ့အတိုင်း customer review တွေကို အနှစ်ချုပ်နိုင်တဲ့ <a href="https://huggingface.co/huggingface-course/mt5-small-finetuned-amazon-en-es" rel="nofollow">model</a> တစ်ခုကို သင်ရရှိပါလိမ့်မယ်။</p> <iframe src="https://course-demos-mt5-small-finetuned-amazon-en-es.hf.space" frameborder="0" height="400" title="Gradio app" class="block dark:hidden container p-0 flex-grow space-iframe" allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe> <p data-svelte-h="svelte-1onralo">ကျွန်တော်တို့ တွေ့မြင်ရမယ့်အတိုင်း၊ ဒီအနှစ်ချုပ်တွေက တိုတောင်းပါတယ်။ ဘာလို့လဲဆိုတော့ ၎င်းတို့ကို customer တွေရဲ့ product reviews တွေမှာ ပေးထားတဲ့ titles တွေကနေ သင်ယူထားလို့ပါပဲ။ ဒီ task အတွက် သင့်လျော်တဲ့ bilingual corpus တစ်ခုကို စုစည်းခြင်းဖြင့် စတင်ကြရအောင်။</p> <h2 class="relative group"><a id="preparing-a-multilingual-corpus" 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="#preparing-a-multilingual-corpus"><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>Multilingual Corpus တစ်ခုကို ပြင်ဆင်ခြင်း</span></h2> <p data-svelte-h="svelte-117t18o">ကျွန်တော်တို့ရဲ့ bilingual summarizer ကို ဖန်တီးဖို့ <a href="https://huggingface.co/datasets/amazon_reviews_multi" rel="nofollow">Multilingual Amazon Reviews Corpus</a> ကို အသုံးပြုပါမယ်။ ဒီ corpus ဟာ ဘာသာစကား ၆ မျိုးနဲ့ Amazon product reviews တွေ ပါဝင်ပြီး multilingual classifiers တွေကို benchmark လုပ်ဖို့အတွက် ပုံမှန်အားဖြင့် အသုံးပြုပါတယ်။ ဒါပေမယ့် review တစ်ခုစီမှာ short title တစ်ခု ပါဝင်တာကြောင့်၊ ကျွန်တော်တို့ရဲ့ model ကနေ သင်ယူဖို့အတွက် titles တွေကို target summaries အဖြစ် အသုံးပြုနိုင်ပါတယ်! စတင်ဖို့ Hugging Face Hub ကနေ English နဲ့ Spanish subsets တွေကို download လုပ်ရအောင်။</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 | |
| spanish_dataset = load_dataset(<span class="hljs-string">"amazon_reviews_multi"</span>, <span class="hljs-string">"es"</span>) | |
| english_dataset = load_dataset(<span class="hljs-string">"amazon_reviews_multi"</span>, <span class="hljs-string">"en"</span>) | |
| english_dataset<!-- 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 -->DatasetDict({ | |
| train: Dataset({ | |
| features: [<span class="hljs-string">'review_id'</span>, <span class="hljs-string">'product_id'</span>, <span class="hljs-string">'reviewer_id'</span>, <span class="hljs-string">'stars'</span>, <span class="hljs-string">'review_body'</span>, <span class="hljs-string">'review_title'</span>, <span class="hljs-string">'language'</span>, <span class="hljs-string">'product_category'</span>], | |
| num_rows: <span class="hljs-number">200000</span> | |
| }) | |
| validation: Dataset({ | |
| features: [<span class="hljs-string">'review_id'</span>, <span class="hljs-string">'product_id'</span>, <span class="hljs-string">'reviewer_id'</span>, <span class="hljs-string">'stars'</span>, <span class="hljs-string">'review_body'</span>, <span class="hljs-string">'review_title'</span>, <span class="hljs-string">'language'</span>, <span class="hljs-string">'product_category'</span>], | |
| num_rows: <span class="hljs-number">5000</span> | |
| }) | |
| test: Dataset({ | |
| features: [<span class="hljs-string">'review_id'</span>, <span class="hljs-string">'product_id'</span>, <span class="hljs-string">'reviewer_id'</span>, <span class="hljs-string">'stars'</span>, <span class="hljs-string">'review_body'</span>, <span class="hljs-string">'review_title'</span>, <span class="hljs-string">'language'</span>, <span class="hljs-string">'product_category'</span>], | |
| num_rows: <span class="hljs-number">5000</span> | |
| }) | |
| })<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-16gt3kh">သင်မြင်ရတဲ့အတိုင်း၊ ဘာသာစကားတစ်ခုစီအတွက် <code>train</code> split မှာ review ၂၀၀,၀၀၀ ရှိပြီး <code>validation</code> နဲ့ <code>test</code> splits တစ်ခုစီအတွက် review ၅,၀၀၀ စီ ရှိပါတယ်။ ကျွန်တော်တို့ စိတ်ဝင်စားတဲ့ review အချက်အလက်တွေက <code>review_body</code> နဲ့ <code>review_title</code> columns တွေမှာ ပါဝင်ပါတယ်။ <a href="/course/chapter5">Chapter 5</a> မှာ သင်ယူခဲ့တဲ့ နည်းလမ်းတွေနဲ့ training set ကနေ random sample တစ်ခုကို ယူတဲ့ ရိုးရှင်းတဲ့ 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_">show_samples</span>(<span class="hljs-params">dataset, num_samples=<span class="hljs-number">3</span>, seed=<span class="hljs-number">42</span></span>): | |
| sample = dataset[<span class="hljs-string">"train"</span>].shuffle(seed=seed).select(<span class="hljs-built_in">range</span>(num_samples)) | |
| <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> sample: | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"\n'>> Title: <span class="hljs-subst">{example[<span class="hljs-string">'review_title'</span>]}</span>'"</span>) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"'>> Review: <span class="hljs-subst">{example[<span class="hljs-string">'review_body'</span>]}</span>'"</span>) | |
| show_samples(english_dataset)<!-- 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">'>> Title: Worked in front position, not rear'</span> | |
| <span class="hljs-string">'>> Review: 3 stars because these are not rear brakes as stated in the item description. At least the mount adapter only worked on the front fork of the bike that I got it for.'</span> | |
| <span class="hljs-string">'>> Title: meh'</span> | |
| <span class="hljs-string">'>> Review: Does it’s job and it’s gorgeous but mine is falling apart, I had to basically put it together again with hot glue'</span> | |
| <span class="hljs-string">'>> Title: Can\'t beat these for the money'</span> | |
| <span class="hljs-string">'>> Review: Bought this for handling miscellaneous aircraft parts and hanger "stuff" that I needed to organize; it really fit the bill. The unit arrived quickly, was well packaged and arrived intact (always a good sign). There are five wall mounts-- three on the top and two on the bottom. I wanted to mount it on the wall, so all I had to do was to remove the top two layers of plastic drawers, as well as the bottom corner drawers, place it when I wanted and mark it; I then used some of the new plastic screw in wall anchors (the 50 pound variety) and it easily mounted to the wall. Some have remarked that they wanted dividers for the drawers, and that they made those. Good idea. My application was that I needed something that I can see the contents at about eye level, so I wanted the fuller-sized drawers. I also like that these are the new plastic that doesn\'t get brittle and split like my older plastic drawers did. I like the all-plastic construction. It\'s heavy duty enough to hold metal parts, but being made of plastic it\'s not as heavy as a metal frame, so you can easily mount it to the wall and still load it up with heavy stuff, or light stuff. No problem there. For the money, you can\'t beat it. Best one of these I\'ve bought to date-- and I\'ve been using some version of these for over forty years.'</span><!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-j5qk4"><p>✏️ <strong>စမ်းသပ်ကြည့်ပါ။</strong> <code>Dataset.shuffle()</code> command မှာ random seed ကို ပြောင်းလဲခြင်းဖြင့် corpus ထဲက အခြား reviews တွေကို လေ့လာကြည့်ပါ။ သင်က Spanish စကားပြောသူဖြစ်တယ်ဆိုရင်၊ <code>spanish_dataset</code> ထဲက reviews အချို့ကို ကြည့်ပြီး titles တွေကလည်း သင့်လျော်တဲ့ summaries တွေလို ဖြစ်နေလားဆိုတာ ကြည့်ပါ။</p></blockquote> <p data-svelte-h="svelte-1heyu88">ဒီ sample က online မှာ ပုံမှန်တွေ့ရတဲ့ reviews အမျိုးမျိုးကို ပြသပါတယ်။ positive ကနေ negative အထိ (ပြီးတော့ နှစ်ခုကြားက အားလုံး) ပါဝင်ပါတယ်။ “meh” title ပါတဲ့ ဥပမာက သိပ်အသုံးဝင်တာ မဟုတ်ပေမယ့်၊ ကျန်တဲ့ titles တွေက reviews တွေရဲ့ ကောင်းမွန်တဲ့ summaries တွေလို ဖြစ်နေပါတယ်။ review ၄၀၀,၀၀၀ လုံးပေါ်မှာ summarization model တစ်ခုကို train လုပ်တာက single GPU တစ်ခုတည်းနဲ့ အချိန်အကြာကြီး ယူရမှာဖြစ်တာကြောင့်၊ ကျွန်တော်တို့က ထုတ်ကုန် domain တစ်ခုတည်းအတွက် summaries တွေ ထုတ်လုပ်တာကိုပဲ အာရုံစိုက်ပါမယ်။ ဘယ် domain တွေကို ရွေးချယ်နိုင်မလဲဆိုတာ သိရှိနိုင်ဖို့ <code>english_dataset</code> ကို <code>pandas.DataFrame</code> သို့ ပြောင်းပြီး product category တစ်ခုစီအတွက် reviews အရေအတွက်ကို တွက်ချက်ကြည့်ရအောင်။</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 -->english_dataset.set_format(<span class="hljs-string">"pandas"</span>) | |
| english_df = english_dataset[<span class="hljs-string">"train"</span>][:] | |
| <span class="hljs-comment"># ထိပ်ဆုံးထုတ်ကုန် ၂၀ အတွက် အရေအတွက်များကို ပြသသည်</span> | |
| english_df[<span class="hljs-string">"product_category"</span>].value_counts()[:<span class="hljs-number">20</span>]<!-- 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 -->home <span class="hljs-number">17679</span> | |
| apparel <span class="hljs-number">15951</span> | |
| wireless <span class="hljs-number">15717</span> | |
| other <span class="hljs-number">13418</span> | |
| beauty <span class="hljs-number">12091</span> | |
| drugstore <span class="hljs-number">11730</span> | |
| kitchen <span class="hljs-number">10382</span> | |
| toy <span class="hljs-number">8745</span> | |
| sports <span class="hljs-number">8277</span> | |
| automotive <span class="hljs-number">7506</span> | |
| lawn_and_garden <span class="hljs-number">7327</span> | |
| home_improvement <span class="hljs-number">7136</span> | |
| pet_products <span class="hljs-number">7082</span> | |
| digital_ebook_purchase <span class="hljs-number">6749</span> | |
| pc <span class="hljs-number">6401</span> | |
| electronics <span class="hljs-number">6186</span> | |
| office_product <span class="hljs-number">5521</span> | |
| shoes <span class="hljs-number">5197</span> | |
| grocery <span class="hljs-number">4730</span> | |
| book <span class="hljs-number">3756</span> | |
| Name: product_category, dtype: int64<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1ov5jvs">English dataset မှာ လူကြိုက်အများဆုံး ထုတ်ကုန်တွေက အိမ်သုံးပစ္စည်းတွေ၊ အဝတ်အထည်တွေနဲ့ wireless electronics တွေ ဖြစ်ပါတယ်။ Amazon theme နဲ့ ဆက်သွားဖို့၊ book reviews တွေကို အနှစ်ချုပ်တာကိုပဲ အာရုံစိုက်ကြရအောင် — ဘာပဲဖြစ်ဖြစ်၊ ဒါက ကုမ္ပဏီတည်ထောင်ခဲ့တာပါပဲ! ဒီအတွက် သင့်လျော်တဲ့ product categories နှစ်ခု (<code>book</code> နဲ့ <code>digital_ebook_purchase</code>) ကို ကျွန်တော်တို့ တွေ့ရပါတယ်။ ဒါကြောင့် ဘာသာစကားနှစ်မျိုးလုံးရှိ datasets တွေကနေ ဒီထုတ်ကုန်တွေအတွက်ပဲ filter လုပ်ရအောင်။ <a href="/course/chapter5">Chapter 5</a> မှာ ကျွန်တော်တို့ တွေ့ခဲ့ရတဲ့အတိုင်း၊ <code>Dataset.filter()</code> function က dataset တစ်ခုကို အလွန်ထိရောက်စွာ slice လုပ်နိုင်တာကြောင့်၊ ဒါကိုလုပ်ဖို့ ရိုးရှင်းတဲ့ 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_">filter_books</span>(<span class="hljs-params">example</span>): | |
| <span class="hljs-keyword">return</span> ( | |
| example[<span class="hljs-string">"product_category"</span>] == <span class="hljs-string">"book"</span> | |
| <span class="hljs-keyword">or</span> example[<span class="hljs-string">"product_category"</span>] == <span class="hljs-string">"digital_ebook_purchase"</span> | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1kehu39">အခု ဒီ function ကို <code>english_dataset</code> နဲ့ <code>spanish_dataset</code> တွေပေါ်မှာ အသုံးပြုတဲ့အခါ၊ ရလဒ်မှာ book categories နဲ့ သက်ဆိုင်တဲ့ rows တွေသာ ပါဝင်ပါလိမ့်မယ်။ filter ကို အသုံးမပြုခင်၊ <code>english_dataset</code> ရဲ့ format ကို <code>"pandas"</code> ကနေ <code>"arrow"</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 -->english_dataset.reset_format()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-acwlm7">ပြီးရင် filter function ကို အသုံးပြုနိုင်ပြီး၊ sanity check တစ်ခုအနေနဲ့ reviews တွေရဲ့ sample တစ်ခုကို ကြည့်ပြီး ဒါတွေက စာအုပ်တွေနဲ့ ပတ်သက်တာ ဟုတ်မဟုတ် စစ်ဆေးကြည့်ရအောင်။</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 -->spanish_books = spanish_dataset.<span class="hljs-built_in">filter</span>(filter_books) | |
| english_books = english_dataset.<span class="hljs-built_in">filter</span>(filter_books) | |
| show_samples(english_books)<!-- 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">'>> Title: I\'m dissapointed.'</span> | |
| <span class="hljs-string">'>> Review: I guess I had higher expectations for this book from the reviews. I really thought I\'d at least like it. The plot idea was great. I loved Ash but, it just didnt go anywhere. Most of the book was about their radio show and talking to callers. I wanted the author to dig deeper so we could really get to know the characters. All we know about Grace is that she is attractive looking, Latino and is kind of a brat. I\'m dissapointed.'</span> | |
| <span class="hljs-string">'>> Title: Good art, good price, poor design'</span> | |
| <span class="hljs-string">'>> Review: I had gotten the DC Vintage calendar the past two years, but it was on backorder forever this year and I saw they had shrunk the dimensions for no good reason. This one has good art choices but the design has the fold going through the picture, so it\'s less aesthetically pleasing, especially if you want to keep a picture to hang. For the price, a good calendar'</span> | |
| <span class="hljs-string">'>> Title: Helpful'</span> | |
| <span class="hljs-string">'>> Review: Nearly all the tips useful and. I consider myself an intermediate to advanced user of OneNote. I would highly recommend.'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-k9eped">ကောင်းပါပြီ၊ reviews တွေဟာ စာအုပ်တွေနဲ့ တိတိကျကျ ပတ်သက်တာ မဟုတ်ဘဲ calendars တွေနဲ့ OneNote လို electronic applications တွေလို အရာတွေကို ရည်ညွှန်းနိုင်တာကို ကျွန်တော်တို့ တွေ့ရပါတယ်။ သို့သော်လည်း၊ domain က summarization model တစ်ခုကို train လုပ်ဖို့အတွက် သင့်တော်ပုံရပါတယ်။ ဒီ task အတွက် သင့်လျော်တဲ့ models အမျိုးမျိုးကို မကြည့်ခင်၊ ကျွန်တော်တို့မှာ နောက်ဆုံး data preparation အနည်းငယ် လုပ်စရာရှိပါသေးတယ်၊ English နဲ့ Spanish reviews တွေကို single <code>DatasetDict</code> object အဖြစ် ပေါင်းစပ်တာပါ။ 🤗 Datasets က အသုံးဝင်တဲ့ <code>concatenate_datasets()</code> function တစ်ခုကို ပံ့ပိုးပေးပြီး (နာမည်က ဖော်ပြထားတဲ့အတိုင်း) <code>Dataset</code> objects နှစ်ခုကို တစ်ခုပေါ်တစ်ခု ထပ်ပေးပါလိမ့်မယ်။ ဒါကြောင့်၊ ကျွန်တော်တို့ရဲ့ bilingual dataset ကို ဖန်တီးဖို့၊ split တစ်ခုစီကို loop လုပ်ပြီး၊ အဲဒီ split အတွက် datasets တွေကို concatenate လုပ်ကာ၊ model က ဘာသာစကားတစ်ခုတည်းကို overfit မဖြစ်စေဖို့ ရလဒ်ကို shuffle လုပ်ပါမယ်။</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> concatenate_datasets, DatasetDict | |
| books_dataset = DatasetDict() | |
| <span class="hljs-keyword">for</span> split <span class="hljs-keyword">in</span> english_books.keys(): | |
| books_dataset[split] = concatenate_datasets( | |
| [english_books[split], spanish_books[split]] | |
| ) | |
| books_dataset[split] = books_dataset[split].shuffle(seed=<span class="hljs-number">42</span>) | |
| <span class="hljs-comment"># ဥပမာအချို့ကို ကြည့်ရှုပါ</span> | |
| show_samples(books_dataset)<!-- 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">'>> Title: Easy to follow!!!!'</span> | |
| <span class="hljs-string">'>> Review: I loved The dash diet weight loss Solution. Never hungry. I would recommend this diet. Also the menus are well rounded. Try it. Has lots of the information need thanks.'</span> | |
| <span class="hljs-string">'>> Title: PARCIALMENTE DAÑADO'</span> | |
| <span class="hljs-string">'>> Review: Me llegó el día que tocaba, junto a otros libros que pedí, pero la caja llegó en mal estado lo cual dañó las esquinas de los libros porque venían sin protección (forro).'</span> | |
| <span class="hljs-string">'>> Title: no lo he podido descargar'</span> | |
| <span class="hljs-string">'>> Review: igual que el anterior'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-nnn85j">ဒါက English နဲ့ Spanish reviews တွေ ရောနှောထားတာ သေချာပါတယ်။ အခု training corpus တစ်ခုရပြီဆိုတော့၊ နောက်ဆုံးစစ်ဆေးရမယ့်အရာက reviews နဲ့ titles တွေထဲက စကားလုံးဖြန့်ဝေမှု (distribution) ပါပဲ။ ဒါက summarization tasks တွေအတွက် အထူးအရေးကြီးပါတယ်။ ဘာလို့လဲဆိုတော့ data ထဲက တိုတောင်းတဲ့ reference summaries တွေက model ကို generated summaries တွေမှာ စကားလုံးတစ်လုံး ဒါမှမဟုတ် နှစ်လုံးပဲ ထုတ်လုပ်အောင် ဘက်လိုက်စေနိုင်လို့ပါ။ အောက်ပါ plots တွေက word distributions တွေကို ပြသထားပြီး၊ titles တွေက စကားလုံး ၁ လုံး၊ ၂ လုံးလောက်ပဲ အလွန်အမင်း skewed ဖြစ်နေတာကို ကျွန်တော်တို့ တွေ့မြင်နိုင်ပါတယ်။</p> <div class="flex justify-center" data-svelte-h="svelte-1pwnbfd"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/review-lengths.svg" alt="Word count distributions for the review titles and texts."> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/review-lengths-dark.svg" alt="Word count distributions for the review titles and texts."></div> <p data-svelte-h="svelte-i6jlj8">ဒီပြဿနာကို ဖြေရှင်းဖို့၊ အလွန်တိုတောင်းတဲ့ titles တွေနဲ့ ဥပမာတွေကို ကျွန်တော်တို့ filter လုပ်ပါမယ်။ ဒါမှ ကျွန်တော်တို့ရဲ့ model က ပိုမိုစိတ်ဝင်စားစရာကောင်းတဲ့ summaries တွေ ထုတ်လုပ်နိုင်ပါလိမ့်မယ်။ English နဲ့ Spanish texts တွေနဲ့ အလုပ်လုပ်နေတာကြောင့်၊ titles တွေကို whitespace ပေါ်မှာ split လုပ်ဖို့ ကြမ်းတမ်းတဲ့ heuristic တစ်ခုကို အသုံးပြုနိုင်ပြီး၊ ကျွန်တော်တို့ရဲ့ ယုံကြည်ရတဲ့ <code>Dataset.filter()</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 -->books_dataset = books_dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">"review_title"</span>].split()) > <span class="hljs-number">2</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-j4l6ky">ကျွန်တော်တို့ corpus ကို ပြင်ဆင်ပြီးပြီဆိုတော့၊ ဒီ task အတွက် သင့်လျော်တဲ့ Transformer models အချို့ကို ကြည့်ရအောင်။</p> <h2 class="relative group"><a id="models-for-text-summarization" 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="#models-for-text-summarization"><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>Text Summarization အတွက် Models များ</span></h2> <p data-svelte-h="svelte-1k3tnq1">သင်စဉ်းစားကြည့်မယ်ဆိုရင်၊ text summarization ဟာ machine translation နဲ့ ဆင်တူတဲ့ task တစ်ခုပါ- review တစ်ခုလို body of text တစ်ခုရှိပြီး၊ input ရဲ့ salient features တွေကို ဖော်ပြတဲ့ ပိုတိုတောင်းတဲ့ version တစ်ခုအဖြစ် “translate” လုပ်ချင်ပါတယ်။ ဒါကြောင့်၊ summarization အတွက် Transformer models အများစုက <a href="/course/chapter1">Chapter 1</a> မှာ ကျွန်တော်တို့ ပထမဆုံး ကြုံတွေ့ခဲ့ရတဲ့ encoder-decoder architecture ကို အသုံးပြုကြပါတယ်။ သို့သော်လည်း၊ few-shot settings မှာ summarization အတွက် အသုံးပြုနိုင်တဲ့ GPT family of models လိုမျိုး ချွင်းချက်အချို့တော့ ရှိပါတယ်။ အောက်ပါဇယားက summarization အတွက် fine-tune လုပ်နိုင်တဲ့ ရေပန်းစားတဲ့ pretrained models အချို့ကို ဖော်ပြထားပါတယ်။</p> <table data-svelte-h="svelte-1c78rwy"><thead><tr><th align="center">Transformer model</th> <th>Description</th> <th align="center">Multilingual?</th></tr></thead> <tbody><tr><td align="center"><a href="https://huggingface.co/gpt2-xl" rel="nofollow">GPT-2</a></td> <td>auto-regressive language model အဖြစ် train ထားသော်လည်း၊ input text ရဲ့ အဆုံးမှာ “TL;DR” ကို ထည့်သွင်းခြင်းဖြင့် GPT-2 ကို summaries တွေ ထုတ်လုပ်စေနိုင်ပါတယ်။</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/google/pegasus-large" rel="nofollow">PEGASUS</a></td> <td>multi-sentence texts တွေထဲက masked sentences တွေကို ခန့်မှန်းဖို့ pretraining objective ကို အသုံးပြုပါတယ်။ ဒီ pretraining objective က vanilla language modeling ထက် summarization နဲ့ ပိုနီးစပ်ပြီး ရေပန်းစားတဲ့ benchmarks တွေမှာ မြင့်မားတဲ့ score ရရှိပါတယ်။</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/t5-base" rel="nofollow">T5</a></td> <td>NLP tasks အားလုံးကို text-to-text framework မှာ ပုံဖော်ပေးတဲ့ universal Transformer architecture; ဥပမာ- document တစ်ခုကို summarize လုပ်ဖို့ model အတွက် input format က <code>summarize: ARTICLE</code> ဖြစ်ပါတယ်။</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/google/mt5-base" rel="nofollow">mT5</a></td> <td>T5 ရဲ့ multilingual version တစ်ခုဖြစ်ပြီး multilingual Common Crawl corpus (mC4) ပေါ်မှာ pretrained လုပ်ထားကာ ဘာသာစကား ၁၀၁ မျိုး ပါဝင်ပါတယ်။</td> <td align="center">✅</td></tr> <tr><td align="center"><a href="https://huggingface.co/facebook/bart-base" rel="nofollow">BART</a></td> <td>encoder နဲ့ decoder stack နှစ်ခုလုံးပါဝင်ပြီး BERT နဲ့ GPT-2 ရဲ့ pretraining schemes တွေကို ပေါင်းစပ်ထားတဲ့ corrupted input ကို reconstruct လုပ်ဖို့ train ထားတဲ့ novel Transformer architecture။</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/facebook/mbart-large-50" rel="nofollow">mBART-50</a></td> <td>BART ရဲ့ multilingual version တစ်ခုဖြစ်ပြီး ဘာသာစကား ၅၀ ပေါ်မှာ pretrained လုပ်ထားပါတယ်။</td> <td align="center">✅</td></tr></tbody></table> <p data-svelte-h="svelte-1fa7ycd">ဒီဇယားကနေ သင်မြင်ရတဲ့အတိုင်း၊ summarization အတွက် Transformer models အများစု (ပြီးတော့ NLP tasks အများစု) ဟာ monolingual ဖြစ်ပါတယ်။ ဒါက English ဒါမှမဟုတ် German လို “high-resource” language တစ်ခုမှာ သင့် task ရှိမယ်ဆိုရင် ကောင်းပါတယ်၊ ဒါပေမယ့် ကမ္ဘာတစ်ဝှမ်းလုံးမှာ အသုံးပြုနေတဲ့ ထောင်နဲ့ချီတဲ့ အခြားဘာသာစကားတွေအတွက်တော့ မကောင်းပါဘူး။ ကံကောင်းစွာနဲ့ပဲ၊ mT5 နဲ့ mBART လိုမျိုး multilingual Transformer models တွေရှိပြီး ဒါတွေက ကူညီကယ်တင်ပေးပါတယ်။ ဒီ models တွေကို language modeling ကို အသုံးပြုပြီး pretrained လုပ်ထားပေမယ့်၊ ကွဲပြားမှုတစ်ခုတော့ ရှိပါတယ်၊ ဘာသာစကားတစ်ခုတည်းရဲ့ corpus ပေါ်မှာ train လုပ်မယ့်အစား၊ ဘာသာစကား ၅၀ ကျော်ရှိတဲ့ texts တွေပေါ်မှာ တစ်ပြိုင်နက်တည်း train လုပ်ထားတာပါ!</p> <p data-svelte-h="svelte-pyhysa">ကျွန်တော်တို့ mT5 ကို အာရုံစိုက်ပါမယ်။ T5 ပေါ်မှာ အခြေခံထားတဲ့ စိတ်ဝင်စားစရာ architecture တစ်ခုဖြစ်ပြီး text-to-text framework မှာ pretrained လုပ်ထားပါတယ်။ T5 မှာ၊ NLP task တိုင်းကို <code>summarize:</code> လိုမျိုး prompt prefix တစ်ခုရဲ့ ပုံစံနဲ့ ဖော်ပြထားပါတယ်။ ဒါက generated text ကို prompt နဲ့ လိုက်လျောညီထွေဖြစ်အောင် model ကို အခြေအနေပေးပါတယ်။ အောက်ပါပုံမှာ ပြသထားတဲ့အတိုင်း၊ ဒါက T5 ကို အလွန်အမင်း versatility ရှိစေပြီး၊ single model တစ်ခုတည်းနဲ့ tasks များစွာကို ဖြေရှင်းနိုင်ပါတယ်!</p> <div class="flex justify-center" data-svelte-h="svelte-k7lnur"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/t5.svg" alt="Different tasks performed by the T5 architecture."> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/t5-dark.svg" alt="Different tasks performed by the T5 architecture."></div> <p data-svelte-h="svelte-1s1szos">mT5 က prefixes တွေကို အသုံးမပြုပေမယ့်၊ T5 ရဲ့ versatility အများစုကို မျှဝေထားပြီး multilingual ဖြစ်တဲ့ အားသာချက်ရှိပါတယ်။ အခု model တစ်ခုကို ရွေးချယ်ပြီးပြီဆိုတော့၊ training အတွက် ကျွန်တော်တို့ရဲ့ data ကို ပြင်ဆင်တာကို ကြည့်ရအောင်။</p> <blockquote class="tip" data-svelte-h="svelte-8nj535"><p>✏️ <strong>စမ်းသပ်ကြည့်ပါ။</strong> ဒီအပိုင်းကို ပြီးအောင်လုပ်ပြီးတာနဲ့၊ mT5 က mBART နဲ့ ဘယ်လောက်ကွာလဲဆိုတာကို mBART ကို တူညီတဲ့ နည်းလမ်းတွေနဲ့ fine-tuning လုပ်ပြီး ကြည့်ပါ။ bonus အမှတ်များအတွက်၊ English reviews တွေပေါ်မှာ T5 ကို fine-tuning လုပ်ကြည့်နိုင်ပါတယ်။ T5 မှာ special prefix prompt ရှိတာကြောင့်၊ အောက်ပါ preprocessing steps တွေမှာ input examples တွေရဲ့ အရှေ့မှာ <code>summarize:</code> ကို ထည့်ဖို့ လိုပါလိမ့်မယ်။</p></blockquote> <h2 class="relative group"><a id="preprocessing-the-data" 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="#preprocessing-the-data"><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>Data များကို Preprocessing လုပ်ခြင်း</span></h2> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/1m7BerpSq8A" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-8asrid">ကျွန်တော်တို့ရဲ့ နောက်ထပ် task က reviews တွေနဲ့ titles တွေကို tokenize လုပ်ပြီး encode လုပ်ဖို့ပါပဲ။ ပုံမှန်အတိုင်း၊ pretrained model checkpoint နဲ့ ဆက်စပ်နေတဲ့ tokenizer ကို load လုပ်ခြင်းဖြင့် စတင်ပါမယ်။ model ကို သင့်လျော်တဲ့ အချိန်ကာလတစ်ခုအတွင်း fine-tune လုပ်နိုင်ဖို့ <code>mt5-small</code> ကို checkpoint အဖြစ် အသုံးပြုပါမယ်။</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> AutoTokenizer | |
| model_checkpoint = <span class="hljs-string">"google/mt5-small"</span> | |
| tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-jcf197"><p>💡 သင်၏ NLP projects ရဲ့ အစောပိုင်းအဆင့်တွေမှာ၊ “small” models class တစ်ခုကို data sample သေးသေးလေးပေါ်မှာ train လုပ်တာက ကောင်းမွန်တဲ့ လုပ်ဆောင်မှုတစ်ခုပါ။ ဒါက end-to-end workflow တစ်ခုဆီကို ပိုမိုမြန်ဆန်စွာ debug လုပ်ပြီး iterate လုပ်နိုင်စေပါတယ်။ ရလဒ်တွေမှာ သင်ယုံကြည်မှုရှိပြီဆိုတာနဲ့၊ model checkpoint ကို ရိုးရှင်းစွာ ပြောင်းလဲခြင်းဖြင့် model ကို အမြဲတိုးချဲ့နိုင်ပါတယ်။</p></blockquote> <p data-svelte-h="svelte-gpkpze">mT5 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 -->inputs = tokenizer(<span class="hljs-string">"I loved reading the Hunger Games!"</span>) | |
| inputs<!-- 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">'input_ids'</span>: [<span class="hljs-number">336</span>, <span class="hljs-number">259</span>, <span class="hljs-number">28387</span>, <span class="hljs-number">11807</span>, <span class="hljs-number">287</span>, <span class="hljs-number">62893</span>, <span class="hljs-number">295</span>, <span class="hljs-number">12507</span>, <span class="hljs-number">1</span>], <span class="hljs-string">'attention_mask'</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-27onl9">ဒီနေရာမှာ <a href="/course/chapter3">Chapter 3</a> မှာ ကျွန်တော်တို့ရဲ့ ပထမဆုံး fine-tuning experiments တွေမှာ ကြုံတွေ့ခဲ့ရတဲ့ ရင်းနှီးတဲ့ <code>input_ids</code> နဲ့ <code>attention_mask</code> တွေကို ကျွန်တော်တို့ တွေ့မြင်နိုင်ပါတယ်။ ဒီ input IDs တွေကို tokenizer ရဲ့ <code>convert_ids_to_tokens()</code> function နဲ့ decode လုပ်ပြီး ဘယ်လို 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 -->tokenizer.convert_ids_to_tokens(inputs.input_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">' I'</span>, <span class="hljs-string">' '</span>, <span class="hljs-string">'loved'</span>, <span class="hljs-string">' reading'</span>, <span class="hljs-string">' the'</span>, <span class="hljs-string">' Hung'</span>, <span class="hljs-string">'er'</span>, <span class="hljs-string">' Games'</span>, <span class="hljs-string">'</s>'</span>]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1lfw636">အထူး Unicode character <code></code> နဲ့ end-of-sequence token <code></s></code> က ကျွန်တော်တို့ SentencePiece tokenizer နဲ့ အလုပ်လုပ်နေတာကို ဖော်ပြပါတယ်။ ဒါက <a href="/course/chapter6">Chapter 6</a> မှာ ဆွေးနွေးခဲ့တဲ့ Unigram segmentation algorithm ပေါ် အခြေခံထားပါတယ်။ Unigram က multilingual corpora တွေအတွက် အထူးအသုံးဝင်ပါတယ်။ ဘာလို့လဲဆိုတော့ SentencePiece ကို accents တွေ၊ punctuation တွေနဲ့ Japanese လို ဘာသာစကားများစွာမှာ whitespace characters တွေ မပါဝင်ဘူးဆိုတဲ့ အချက်တွေနဲ့ ပတ်သက်ပြီး agnostic ဖြစ်စေလို့ပါ။</p> <p data-svelte-h="svelte-opa9hr">ကျွန်တော်တို့ corpus ကို tokenize လုပ်ဖို့အတွက် summarization နဲ့ ဆက်စပ်နေတဲ့ သိမ်မွေ့မှုတစ်ခုကို ဖြေရှင်းရပါမယ်၊ ကျွန်တော်တို့ရဲ့ labels တွေကလည်း text ဖြစ်တာကြောင့်၊ ၎င်းတို့ဟာ model ရဲ့ maximum context size ကို ကျော်လွန်သွားနိုင်ပါတယ်။ ဒါက reviews တွေနဲ့ titles တွေ နှစ်ခုလုံးကို truncation လုပ်ဖို့ လိုအပ်တယ်လို့ ဆိုလိုပါတယ်။ ဒါမှ ကျွန်တော်တို့ model ကို အလွန်အမင်း ရှည်လျားတဲ့ inputs တွေ ပေးပို့တာကို ရှောင်ရှားနိုင်ပါလိမ့်မယ်။ 🤗 Transformers မှာရှိတဲ့ tokenizers တွေက input တွေနဲ့ ပြိုင်တူ labels တွေကို tokenize လုပ်နိုင်စေမယ့် အသုံးဝင်တဲ့ <code>text_target</code> argument ကို ပံ့ပိုးပေးပါတယ်။ mT5 အတွက် inputs နဲ့ targets တွေကို ဘယ်လိုလုပ်ဆောင်လဲဆိုတဲ့ ဥပမာတစ်ခုကတော့ ဒီမှာပါ။</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 -->max_input_length = <span class="hljs-number">512</span> | |
| max_target_length = <span class="hljs-number">30</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>): | |
| model_inputs = tokenizer( | |
| examples[<span class="hljs-string">"review_body"</span>], | |
| max_length=max_input_length, | |
| truncation=<span class="hljs-literal">True</span>, | |
| ) | |
| labels = tokenizer( | |
| examples[<span class="hljs-string">"review_title"</span>], max_length=max_target_length, truncation=<span class="hljs-literal">True</span> | |
| ) | |
| model_inputs[<span class="hljs-string">"labels"</span>] = labels[<span class="hljs-string">"input_ids"</span>] | |
| <span class="hljs-keyword">return</span> model_inputs<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-o2sts3">ဘာတွေဖြစ်နေလဲဆိုတာ နားလည်ဖို့ ဒီ code ကို ကြည့်ရအောင်။ ပထမဆုံး ကျွန်တော်တို့ လုပ်ခဲ့တာက <code>max_input_length</code> နဲ့ <code>max_target_length</code> အတွက် တန်ဖိုးတွေ သတ်မှတ်ခဲ့တာပါ။ ဒါတွေက ကျွန်တော်တို့ရဲ့ reviews တွေနဲ့ titles တွေ ဘယ်လောက်ရှည်နိုင်လဲဆိုတဲ့ အပေါ်ဆုံးကန့်သတ်ချက်တွေကို သတ်မှတ်ပါတယ်။ review body က title ထက် အများကြီး ပိုကြီးတာကြောင့်၊ ကျွန်တော်တို့ ဒီတန်ဖိုးတွေကို အချိုးကျ ပြောင်းလဲထားပါတယ်။</p> <p data-svelte-h="svelte-tbjp4x"><code>preprocess_function()</code> နဲ့ဆိုရင်၊ ဒီသင်တန်းတစ်လျှောက်လုံး ကျွန်တော်တို့ ကျယ်ကျယ်ပြန့်ပြန့် အသုံးပြုခဲ့တဲ့ အသုံးဝင်တဲ့ <code>Dataset.map()</code> function ကို အသုံးပြုပြီး corpus တစ်ခုလုံးကို tokenize လုပ်တာက ရိုးရှင်းတဲ့ ကိစ္စတစ်ခုပါ။</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 -->tokenized_datasets = books_dataset.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-11sb1m">အခု corpus ကို preprocessed လုပ်ပြီးပြီဆိုတော့၊ summarization အတွက် ပုံမှန်အသုံးပြုတဲ့ metrics အချို့ကို ကြည့်ရအောင်။ ကျွန်တော်တို့ တွေ့မြင်ရမယ့်အတိုင်း၊ machine-generated text ရဲ့ အရည်အသွေးကို တိုင်းတာရာမှာ မှော်ဆန်တဲ့ ဖြေရှင်းနည်းတစ်ခု မရှိပါဘူး။</p> <blockquote class="tip" data-svelte-h="svelte-1lmk5s8"><p>💡 အပေါ်က <code>Dataset.map()</code> function မှာ <code>batched=True</code> ကို အသုံးပြုခဲ့တာကို သင်သတိထားမိပါလိမ့်မယ်။ ဒါက ဥပမာတွေကို batches of 1,000 (default) နဲ့ encode လုပ်ပြီး 🤗 Transformers မှာရှိတဲ့ fast tokenizers တွေရဲ့ multithreading စွမ်းရည်တွေကို အသုံးပြုနိုင်စေပါတယ်။ ဖြစ်နိုင်ရင်၊ သင့် preprocessing ကနေ အကောင်းဆုံးရရှိဖို့ <code>batched=True</code> ကို အသုံးပြုဖို့ ကြိုးစားပါ။</p></blockquote> <h2 class="relative group"><a id="metrics-for-text-summarization" 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="#metrics-for-text-summarization"><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>Text Summarization အတွက် Metrics များ</span></h2> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/TMshhnrEXlg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-d09mxc">ဒီသင်တန်းမှာ ကျွန်တော်တို့ ဖော်ပြခဲ့တဲ့ အခြား tasks တွေနဲ့ နှိုင်းယှဉ်ရင်၊ summarization ဒါမှမဟုတ် translation လို text generation tasks တွေရဲ့ စွမ်းဆောင်ရည်ကို တိုင်းတာတာက သိပ်မရိုးရှင်းပါဘူး။ ဥပမာ၊ “I loved reading the Hunger Games” လို review တစ်ခုကို ပေးထားရင်၊ “I loved the Hunger Games” ဒါမှမဟုတ် “Hunger Games is a great read” လိုမျိုး မှန်ကန်တဲ့ summaries များစွာ ရှိနိုင်ပါတယ်။ generated summary နဲ့ label ကြားမှာ တိကျတဲ့ ကိုက်ညီမှုမျိုးကို အသုံးပြုတာက ကောင်းမွန်တဲ့ ဖြေရှင်းနည်း မဟုတ်ဘူးဆိုတာ ရှင်းပါတယ်။ ဘာလို့လဲဆိုတော့ ကျွန်တော်တို့ အားလုံးမှာ ကိုယ်ပိုင်ရေးသားဟန် ရှိကြတာကြောင့် လူသားတွေတောင် ဒီလို metric အောက်မှာ ကောင်းကောင်းလုပ်ဆောင်နိုင်မှာ မဟုတ်ပါဘူး။</p> <p data-svelte-h="svelte-1clc43n">Summarization အတွက် အသုံးအများဆုံး metrics တွေထဲက တစ်ခုကတော့ <a href="https://en.wikipedia.org/wiki/ROUGE_(metric)" rel="nofollow">ROUGE score</a> (Recall-Oriented Understudy for Gisting Evaluation ရဲ့ အတိုကောက်) ဖြစ်ပါတယ်။ ဒီ metric ရဲ့ အခြေခံစိတ်ကူးက generated summary တစ်ခုကို လူသားတွေ ဖန်တီးထားတဲ့ reference summaries အစုအဝေးတစ်ခုနဲ့ နှိုင်းယှဉ်ဖို့ပါပဲ။ ဒါကို ပိုပြီး တိကျအောင် လုပ်ဖို့၊ အောက်ပါ summaries နှစ်ခုကို နှိုင်းယှဉ်ချင်တယ်လို့ ယူဆပါစို့။</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 -->generated_summary = <span class="hljs-string">"I absolutely loved reading the Hunger Games"</span> | |
| reference_summary = <span class="hljs-string">"I loved reading the Hunger Games"</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1irr7mo">ဒါတွေကို နှိုင်းယှဉ်တဲ့ နည်းလမ်းတစ်ခုက ထပ်နေတဲ့ စကားလုံးအရေအတွက်ကို ရေတွက်တာ ဖြစ်နိုင်ပြီး၊ ဒီကိစ္စမှာ ၆ လုံး ရှိပါလိမ့်မယ်။ သို့သော်လည်း ဒါက အနည်းငယ် ကြမ်းတမ်းတာကြောင့်၊ ROUGE က ထပ်နေမှုအတွက် <em>precision</em> နဲ့ <em>recall</em> scores တွေကို တွက်ချက်ခြင်းပေါ်မှာ အခြေခံထားပါတယ်။</p> <blockquote class="tip" data-svelte-h="svelte-iedh70"><p>🙋 ဒါက precision နဲ့ recall အကြောင်း သင်ပထမဆုံး ကြားဖူးတာဆိုရင် မစိုးရိမ်ပါနဲ့ — ဒါတွေ အားလုံးကို ရှင်းလင်းအောင် အတူတူ ဥပမာအချို့ကို ကြည့်သွားပါမယ်။ ဒီ metrics တွေကို classification tasks တွေမှာ ပုံမှန်တွေ့ရတာကြောင့်၊ အဲဒီ context မှာ precision နဲ့ recall တွေကို ဘယ်လိုသတ်မှတ်ထားလဲ နားလည်ချင်တယ်ဆိုရင် <code>scikit-learn</code> <a href="https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html" rel="nofollow">guides</a> ကို စစ်ဆေးကြည့်ဖို့ ကျွန်တော်တို့ အကြံပြုပါတယ်။</p></blockquote> <p>ROUGE အတွက်၊ recall က generated summary က reference summary ရဲ့ ဘယ်လောက်အတိုင်းအတာအထိ ဖမ်းယူနိုင်သလဲဆိုတာကို တိုင်းတာပါတယ်။ စကားလုံးတွေကိုပဲ နှိုင်းယှဉ်နေမယ်ဆိုရင်၊ recall ကို အောက်ပါ formula နဲ့ တွက်ချက်နိုင်ပါတယ်- | |
| <!-- HTML_TAG_START --><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">R</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">l</mi></mrow><mo>=</mo><mfrac><mrow><mi mathvariant="normal">N</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">g</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi></mrow><mrow><mi mathvariant="normal">T</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mtext> </mtext><mi mathvariant="normal">n</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi><mtext> </mtext><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mtext> </mtext><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">e</mi><mtext> </mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">y</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex"> \mathrm{Recall} = \frac{\mathrm{Number\,of\,overlapping\, words}}{\mathrm{Total\, number\, of\, words\, in\, reference\, summary}} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord"><span class="mord mathrm">Recall</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2519em;vertical-align:-0.8804em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3714em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Total</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">in</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">reference</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">summary</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">overlapping</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.8804em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span><!-- HTML_TAG_END --></p> <p>ကျွန်တော်တို့ရဲ့ အပေါ်က ရိုးရှင်းတဲ့ ဥပမာအတွက်၊ ဒီ formula က 6/6 = 1 ဆိုတဲ့ perfect recall ကို ပေးပါတယ်၊ ဆိုလိုတာက reference summary ထဲက စကားလုံးအားလုံးကို model က ထုတ်လုပ်ခဲ့ပါတယ်။ ဒါက ကောင်းမွန်တယ်လို့ ထင်ရပေမယ့်၊ ကျွန်တော်တို့ရဲ့ generated summary က “I really really loved reading the Hunger Games all night” ဖြစ်ခဲ့မယ်ဆိုရင် ဘယ်လိုလုပ်မလဲဆိုတာ စဉ်းစားကြည့်ပါ။ ဒါကလည်း perfect recall ရမှာဖြစ်ပေမယ့်၊ verbose ဖြစ်တာကြောင့် ပိုဆိုးတဲ့ summary ဖြစ်တယ်လို့ ငြင်းဆိုနိုင်ပါတယ်။ ဒီလိုအခြေအနေတွေကို ဖြေရှင်းဖို့ precision ကိုလည်း ကျွန်တော်တို့ တွက်ချက်ပါတယ်။ ROUGE context မှာ precision က generated summary ရဲ့ ဘယ်လောက်အတိုင်းအတာအထိ relevant ဖြစ်လဲဆိုတာကို တိုင်းတာပါတယ်။ | |
| <!-- HTML_TAG_START --><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">P</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">n</mi></mrow><mo>=</mo><mfrac><mrow><mi mathvariant="normal">N</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">g</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi></mrow><mrow><mi mathvariant="normal">T</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mtext> </mtext><mi mathvariant="normal">n</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi><mtext> </mtext><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mtext> </mtext><mi mathvariant="normal">g</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">d</mi><mtext> </mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">y</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex"> \mathrm{Precision} = \frac{\mathrm{Number\,of\,overlapping\, words}}{\mathrm{Total\, number\, of\, words\, in\, generated\, summary}} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord"><span class="mord mathrm">Precision</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2519em;vertical-align:-0.8804em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3714em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Total</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">in</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">generated</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">summary</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">overlapping</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.8804em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span><!-- HTML_TAG_END --></p> <p data-svelte-h="svelte-1me1k2m">ဒါကို ကျွန်တော်တို့ရဲ့ verbose summary ပေါ်မှာ အသုံးပြုတဲ့အခါ 6/10 = 0.6 ဆိုတဲ့ precision ကို ပေးပါတယ်။ ဒါက ကျွန်တော်တို့ရဲ့ ပိုတိုတဲ့ summary က ရရှိခဲ့တဲ့ 6/7 = 0.86 precision ထက် သိသိသာသာ ဆိုးပါတယ်။ လက်တွေ့မှာတော့ precision နဲ့ recall နှစ်ခုလုံးကို ပုံမှန်တွက်ချက်ပြီး၊ F1-score (precision နဲ့ recall ရဲ့ harmonic mean) ကို ဖော်ပြပါတယ်။ ဒါကို 🤗 Datasets မှာ <code>rouge_score</code> package ကို အရင် install လုပ်ခြင်းဖြင့် လွယ်လွယ်ကူကူ လုပ်ဆောင်နိုင်ပါတယ်။</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 -->!pip install rouge_score<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-g3gpd8">ပြီးရင် ROUGE metric ကို အောက်ပါအတိုင်း load လုပ်ပါ။</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 | |
| rouge_score = evaluate.load(<span class="hljs-string">"rouge"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-929k96">ပြီးရင် <code>rouge_score.compute()</code> function ကို အသုံးပြုပြီး metrics အားလုံးကို တစ်ပြိုင်နက်တည်း တွက်ချက်နိုင်ပါတယ်။</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 -->scores = rouge_score.compute( | |
| predictions=[generated_summary], references=[reference_summary] | |
| ) | |
| scores<!-- 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">'rouge1'</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)), | |
| <span class="hljs-string">'rouge2'</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>), mid=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>), high=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>)), | |
| <span class="hljs-string">'rougeL'</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)), | |
| <span class="hljs-string">'rougeLsum'</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>))}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-in8cmf">ဒီ output ထဲမှာ အချက်အလက်တွေ အများကြီးရှိနေတယ် — ဒါတွေအားလုံးက ဘာကိုဆိုလိုတာလဲ။ ပထမဆုံး၊ 🤗 Datasets က precision, recall နဲ့ F1-score အတွက် confidence intervals တွေကို တကယ်တွက်ချက်ပါတယ်၊ ဒါတွေက သင်ဒီနေရာမှာ မြင်နိုင်တဲ့ <code>low</code>, <code>mid</code>, နဲ့ <code>high</code> attributes တွေပါ။ ဒါ့အပြင်၊ 🤗 Datasets က generated နဲ့ reference summaries တွေကို နှိုင်းယှဉ်တဲ့အခါ မတူညီတဲ့ text granularity အမျိုးအစားတွေပေါ်မှာ အခြေခံထားတဲ့ ROUGE scores အမျိုးမျိုးကို တွက်ချက်ပါတယ်။ <code>rouge1</code> variant က unigrams တွေရဲ့ ထပ်နေမှုဖြစ်ပါတယ် — ဒါက စကားလုံးတွေရဲ့ ထပ်နေမှုကို ဖော်ပြတဲ့ လှပတဲ့ နည်းလမ်းတစ်ခုဖြစ်ပြီး၊ ကျွန်တော်တို့ အပေါ်မှာ ဆွေးနွေးခဲ့တဲ့ metric နဲ့ အတိအကျတူညီပါတယ်။ ဒါကို စစ်ဆေးဖို့၊ ကျွန်တော်တို့ scores ရဲ့ <code>mid</code> value ကို ထုတ်ယူကြည့်ရအောင်။</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 -->scores[<span class="hljs-string">"rouge1"</span>].mid<!-- 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 -->Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-dvgavz">ကောင်းပါပြီ၊ precision နဲ့ recall numbers တွေက ကိုက်ညီပါတယ်။ အခု ကျန်တဲ့ ROUGE scores တွေက ဘာတွေလဲ။ <code>rouge2</code> က bigrams တွေရဲ့ ထပ်နေမှုကို တိုင်းတာပါတယ် (စကားလုံးအတွဲတွေရဲ့ ထပ်နေမှုကို စဉ်းစားပါ)၊ <code>rougeL</code> နဲ့ <code>rougeLsum</code> က generated နဲ့ reference summaries တွေမှာ အရှည်ဆုံး common substrings တွေကို ရှာဖွေခြင်းဖြင့် အရှည်ဆုံး ကိုက်ညီတဲ့ စကားလုံး sequence တွေကို တိုင်းတာပါတယ်။ <code>rougeLsum</code> ထဲက “sum” ဆိုတာက ဒီ metric ကို summary တစ်ခုလုံးပေါ်မှာ တွက်ချက်တယ်ဆိုတာကို ရည်ညွှန်းပြီး၊ <code>rougeL</code> ကတော့ တစ်ဦးချင်းစီ sentence တွေရဲ့ ပျမ်းမျှအဖြစ် တွက်ချက်ပါတယ်။</p> <blockquote class="tip" data-svelte-h="svelte-1navhzu"><p>✏️ <strong>စမ်းသပ်ကြည့်ပါ။</strong> generated နဲ့ reference summary ရဲ့ သင့်ကိုယ်ပိုင် ဥပမာတစ်ခုကို ဖန်တီးပြီး ရလဒ် ROUGE scores တွေက precision နဲ့ recall အတွက် formulas တွေပေါ် အခြေခံထားတဲ့ manual calculation နဲ့ ကိုက်ညီခြင်းရှိမရှိ ကြည့်ပါ။ bonus အမှတ်များအတွက်၊ text ကို bigrams တွေအဖြစ် ခွဲပြီး <code>rouge2</code> metric အတွက် precision နဲ့ recall ကို နှိုင်းယှဉ်ပါ။</p></blockquote> <p data-svelte-h="svelte-1vg0oh5">ဒီ ROUGE scores တွေကို ကျွန်တော်တို့ model ရဲ့ စွမ်းဆောင်ရည်ကို ခြေရာခံဖို့ အသုံးပြုပါမယ်၊ ဒါပေမယ့် ဒါကို မလုပ်ဆောင်ခင်၊ ကောင်းမွန်တဲ့ NLP practitioners တိုင်း လုပ်ဆောင်သင့်တဲ့အရာတစ်ခုကို လုပ်ကြရအောင်- strong, yet simple baseline တစ်ခုကို ဖန်တီးတာပါ။</p> <h3 class="relative group"><a id="creating-a-strong-baseline" 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="#creating-a-strong-baseline"><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>Strong Baseline တစ်ခုကို ဖန်တီးခြင်း</span></h3> <p data-svelte-h="svelte-14zkhvi">Text summarization အတွက် common baseline တစ်ခုကတော့ article တစ်ခုရဲ့ ပထမဆုံး sentences သုံးခုကို ရိုးရှင်းစွာ ယူတာပါပဲ၊ ဒါကို မကြာခဏ <em>lead-3</em> baseline လို့ ခေါ်ပါတယ်။ Sentence boundaries တွေကို ခြေရာခံဖို့ full stops တွေကို ကျွန်တော်တို့ အသုံးပြုနိုင်ပေမယ့်၊ “U.S.” ဒါမှမဟုတ် “U.N.” လို acronyms တွေမှာ ဒါက အဆင်မပြေနိုင်ပါဘူး — ဒါကြောင့် ဒါတွေလို အခြေအနေတွေကို ပိုကောင်းကောင်း ကိုင်တွယ်နိုင်မယ့် algorithm ပါဝင်တဲ့ <code>nltk</code> library ကို ကျွန်တော်တို့ အသုံးပြုပါမယ်။ ဒီ package ကို <code>pip</code> ကို အသုံးပြုပြီး အောက်ပါအတိုင်း install လုပ်နိုင်ပါတယ်။</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 -->!pip install nltk<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-14v3ln4">ပြီးရင် punctuation rules တွေကို download လုပ်ပါ။</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> nltk | |
| nltk.download(<span class="hljs-string">"punkt"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-9f82">နောက်တစ်ဆင့်အနေနဲ့၊ <code>nltk</code> ကနေ sentence tokenizer ကို import လုပ်ပြီး review တစ်ခုထဲက ပထမဆုံး sentences သုံးခုကို ထုတ်ယူဖို့ ရိုးရှင်းတဲ့ function တစ်ခုကို ဖန်တီးပါမယ်။ text summarization မှာ convention က summary တစ်ခုစီကို newline နဲ့ ခွဲခြားဖို့ပါပဲ၊ ဒါကြောင့် ဒါကို ထည့်သွင်းပြီး training example တစ်ခုပေါ်မှာ စမ်းသပ်ကြည့်ရအောင်။</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> nltk.tokenize <span class="hljs-keyword">import</span> sent_tokenize | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">three_sentence_summary</span>(<span class="hljs-params">text</span>): | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">"\n"</span>.join(sent_tokenize(text)[:<span class="hljs-number">3</span>]) | |
| <span class="hljs-built_in">print</span>(three_sentence_summary(books_dataset[<span class="hljs-string">"train"</span>][<span class="hljs-number">1</span>][<span class="hljs-string">"review_body"</span>]))<!-- 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">'I grew up reading Koontz, and years ago, I stopped,convinced i had "outgrown" him.'</span> | |
| <span class="hljs-string">'Still,when a friend was looking for something suspenseful too read, I suggested Koontz.'</span> | |
| <span class="hljs-string">'She found Strangers.'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fb16cg">ဒါက အလုပ်ဖြစ်ပုံရပါတယ်။ ဒါကြောင့် အခု ဒီ “summaries” တွေကို dataset တစ်ခုကနေ ထုတ်ယူပြီး baseline အတွက် ROUGE scores တွေကို တွက်ချက်ပေးမယ့် function တစ်ခုကို implement လုပ်ရအောင်။</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_">evaluate_baseline</span>(<span class="hljs-params">dataset, metric</span>): | |
| summaries = [three_sentence_summary(text) <span class="hljs-keyword">for</span> text <span class="hljs-keyword">in</span> dataset[<span class="hljs-string">"review_body"</span>]] | |
| <span class="hljs-keyword">return</span> metric.compute(predictions=summaries, references=dataset[<span class="hljs-string">"review_title"</span>])<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1inb3c">ပြီးရင် ဒီ function ကို အသုံးပြုပြီး validation set ပေါ်မှာ ROUGE scores တွေကို တွက်ချက်နိုင်ပြီး Pandas ကို အသုံးပြုပြီး အနည်းငယ် ပိုကောင်းအောင် ပြင်ဆင်နိုင်ပါတယ်။</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> pandas <span class="hljs-keyword">as</span> pd | |
| score = evaluate_baseline(books_dataset[<span class="hljs-string">"validation"</span>], rouge_score) | |
| rouge_names = [<span class="hljs-string">"rouge1"</span>, <span class="hljs-string">"rouge2"</span>, <span class="hljs-string">"rougeL"</span>, <span class="hljs-string">"rougeLsum"</span>] | |
| rouge_dict = <span class="hljs-built_in">dict</span>((rn, <span class="hljs-built_in">round</span>(score[rn].mid.fmeasure * <span class="hljs-number">100</span>, <span class="hljs-number">2</span>)) <span class="hljs-keyword">for</span> rn <span class="hljs-keyword">in</span> rouge_names) | |
| rouge_dict<!-- 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">'rouge1'</span>: <span class="hljs-number">16.74</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">8.83</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">15.6</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">15.96</span>}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-d1myoa"><code>rouge2</code> score က ကျန်တာတွေထက် သိသိသာသာ နိမ့်နေတာကို ကျွန်တော်တို့ တွေ့မြင်နိုင်ပါတယ်။ ဒါက review titles တွေဟာ ပုံမှန်အားဖြင့် တိုတောင်းပြီး lead-3 baseline ကတော့ အလွန် verbose ဖြစ်တာကို ရောင်ပြန်ဟပ်နေတာ ဖြစ်နိုင်ပါတယ်။ အခု ကျွန်တော်တို့မှာ အလုပ်လုပ်ဖို့ ကောင်းမွန်တဲ့ baseline တစ်ခုရပြီဆိုတော့၊ mT5 ကို fine-tuning လုပ်တာကို ကျွန်တော်တို့ အာရုံစိုက်ရအောင်။</p> <h2 class="relative group"><a id="fine-tuning-mt5-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-mt5-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 ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း</span></h2> <p data-svelte-h="svelte-1mussbj">Summarization အတွက် model တစ်ခုကို fine-tuning လုပ်တာက ဒီအခန်းမှာ ကျွန်တော်တို့ ဖော်ပြခဲ့တဲ့ အခြား tasks တွေနဲ့ အလွန်ဆင်တူပါတယ်။ ပထမဆုံး လုပ်ရမှာက <code>mt5-small</code> checkpoint ကနေ pretrained model ကို load လုပ်ဖို့ပါပဲ။ Summarization က sequence-to-sequence task ဖြစ်တာကြောင့်၊ <code>AutoModelForSeq2SeqLM</code> class နဲ့ model ကို load လုပ်နိုင်ပြီး၊ ဒါက weights တွေကို အလိုအလျောက် download လုပ်ပြီး cache လုပ်ပါလိမ့်မယ်။</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> AutoModelForSeq2SeqLM | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-t9gl4q"><p>💡 downstream task တစ်ခုပေါ်မှာ model ကို fine-tuning လုပ်တာနဲ့ ပတ်သက်တဲ့ warnings တွေ ဘာကြောင့် မတွေ့ရလဲဆိုတာ သင်တွေးနေမယ်ဆိုရင်၊ ဒါက sequence-to-sequence tasks တွေအတွက် network ရဲ့ weights အားလုံးကို ကျွန်တော်တို့ ထိန်းသိမ်းထားလို့ပါပဲ။ <a href="/course/chapter3">Chapter 3</a> မှာရှိတဲ့ ကျွန်တော်တို့ရဲ့ text classification model နဲ့ နှိုင်းယှဉ်ကြည့်ပါ။ အဲဒီမှာ pretrained model ရဲ့ head ကို randomly initialized network တစ်ခုနဲ့ အစားထိုးခဲ့ပါတယ်။</p></blockquote> <p data-svelte-h="svelte-qf2hby">နောက်တစ်ဆင့်အနေနဲ့၊ Hugging Face Hub ကို log in လုပ်ဖို့ လိုပါတယ်။ သင် ဒီ code ကို notebook ထဲမှာ run နေတယ်ဆိုရင်၊ အောက်ပါ utility 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">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login | |
| notebook_login()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1vfrw6a">ဒါက သင်၏ credentials တွေကို ထည့်သွင်းနိုင်မယ့် widget တစ်ခုကို ပြသပါလိမ့်မယ်။ ဒါမှမဟုတ်၊ ဒီ command ကို သင့် terminal မှာ run ပြီး အဲဒီမှာ log in လုပ်နိုင်ပါတယ်။</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 -->huggingface-<span class="hljs-keyword">cli</span> login<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fiel1h">training လုပ်နေစဉ် ROUGE scores တွေ တွက်ချက်နိုင်ဖို့ summaries တွေ ထုတ်လုပ်ဖို့ ကျွန်တော်တို့ လိုအပ်ပါလိမ့်မယ်။ ကံကောင်းစွာနဲ့ပဲ၊ 🤗 Transformers က ဒါကို ကျွန်တော်တို့အတွက် အလိုအလျောက် လုပ်ဆောင်ပေးနိုင်တဲ့ dedicated <code>Seq2SeqTrainingArguments</code> နဲ့ <code>Seq2SeqTrainer</code> classes တွေကို ပံ့ပိုးပေးပါတယ်။ ဒါက ဘယ်လိုအလုပ်လုပ်လဲဆိုတာ ကြည့်ဖို့၊ ကျွန်တော်တို့ရဲ့ experiments တွေအတွက် hyperparameters တွေနဲ့ အခြား arguments တွေကို အရင်ဆုံး သတ်မှတ်ရအောင်။</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> Seq2SeqTrainingArguments | |
| batch_size = <span class="hljs-number">8</span> | |
| num_train_epochs = <span class="hljs-number">8</span> | |
| <span class="hljs-comment"># epoch တိုင်းမှာ training loss ကို ပြသပါ</span> | |
| logging_steps = <span class="hljs-built_in">len</span>(tokenized_datasets[<span class="hljs-string">"train"</span>]) // batch_size | |
| model_name = model_checkpoint.split(<span class="hljs-string">"/"</span>)[-<span class="hljs-number">1</span>] | |
| args = Seq2SeqTrainingArguments( | |
| output_dir=<span class="hljs-string">f"<span class="hljs-subst">{model_name}</span>-finetuned-amazon-en-es"</span>, | |
| evaluation_strategy=<span class="hljs-string">"epoch"</span>, | |
| learning_rate=<span class="hljs-number">5.6e-5</span>, | |
| per_device_train_batch_size=batch_size, | |
| per_device_eval_batch_size=batch_size, | |
| weight_decay=<span class="hljs-number">0.01</span>, | |
| save_total_limit=<span class="hljs-number">3</span>, | |
| num_train_epochs=num_train_epochs, | |
| predict_with_generate=<span class="hljs-literal">True</span>, | |
| logging_steps=logging_steps, | |
| push_to_hub=<span class="hljs-literal">True</span>, | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1c8kfdq">ဒီနေရာမှာ၊ <code>predict_with_generate</code> argument ကို evaluation လုပ်နေစဉ် summaries တွေ ထုတ်လုပ်သင့်တယ်ဆိုတာကို ဖော်ပြဖို့ သတ်မှတ်ထားတာကြောင့်၊ epoch တစ်ခုစီအတွက် ROUGE scores တွေကို ကျွန်တော်တို့ တွက်ချက်နိုင်ပါတယ်။ <a href="/course/chapter1">Chapter 1</a> မှာ ဆွေးနွေးခဲ့တဲ့အတိုင်း၊ decoder က tokens တွေကို တစ်ခုပြီးတစ်ခု ခန့်မှန်းခြင်းဖြင့် inference ကို လုပ်ဆောင်ပါတယ်၊ ဒါကို model ရဲ့ <code>generate()</code> method နဲ့ implement လုပ်ထားပါတယ်။ <code>predict_with_generate=True</code> လို့ သတ်မှတ်ခြင်းက <code>Seq2SeqTrainer</code> ကို evaluation အတွက် အဲဒီ method ကို အသုံးပြုဖို့ ပြောတာပါ။ ကျွန်တော်တို့က learning rate၊ epochs အရေအတွက်နဲ့ weight decay လိုမျိုး default hyperparameters အချို့ကိုလည်း ချိန်ညှိထားပြီး၊ training လုပ်နေစဉ် checkpoints ၃ ခုအထိသာ save လုပ်ဖို့ <code>save_total_limit</code> option ကို သတ်မှတ်ထားပါတယ် — ဒါက mT5 ရဲ့ “small” version ကတောင် hard drive space တစ် GB လောက် အသုံးပြုတာကြောင့်၊ ကျွန်တော်တို့ save လုပ်တဲ့ copies အရေအတွက်ကို ကန့်သတ်ခြင်းဖြင့် နေရာအနည်းငယ် ချွေတာနိုင်လို့ပါပဲ။</p> <p data-svelte-h="svelte-18n7y4h"><code>push_to_hub=True</code> argument က training ပြီးတာနဲ့ model ကို Hub ကို push လုပ်နိုင်စေပါလိမ့်မယ်၊ repository ကို သင့် user profile အောက်မှာ <code>output_dir</code> က သတ်မှတ်ထားတဲ့ နေရာမှာ တွေ့ရပါလိမ့်မယ်။ သင် push လုပ်ချင်တဲ့ repository ရဲ့ နာမည်ကို <code>hub_model_id</code> argument နဲ့ သတ်မှတ်နိုင်တယ်ဆိုတာ သတိပြုပါ (အထူးသဖြင့်၊ organization တစ်ခုသို့ push လုပ်ဖို့ ဒီ argument ကို အသုံးပြုရပါလိမ့်မယ်)။ ဥပမာ၊ ကျွန်တော်တို့ model ကို <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a> ကို push လုပ်တဲ့အခါ၊ <code>Seq2SeqTrainingArguments</code> မှာ <code>hub_model_id="huggingface-course/mt5-finetuned-amazon-en-es"</code> ကို ထည့်သွင်းခဲ့ပါတယ်။</p> <p data-svelte-h="svelte-1yncma2">နောက်တစ်ဆင့်အနေနဲ့ trainer ကို <code>compute_metrics()</code> function တစ်ခု ပေးဖို့ လိုအပ်ပါတယ်။ ဒါမှ training လုပ်နေစဉ် ကျွန်တော်တို့ model ကို evaluate လုပ်နိုင်မှာပါ။ summarization အတွက် ဒါက model ရဲ့ predictions တွေပေါ်မှာ <code>rouge_score.compute()</code> ကို ရိုးရှင်းစွာ ခေါ်တာထက် အနည်းငယ် ပိုရှုပ်ထွေးပါတယ်။ ဘာလို့လဲဆိုတော့ ROUGE scores တွေ တွက်ချက်နိုင်ဖို့အတွက် outputs တွေနဲ့ labels တွေကို text အဖြစ် <em>decode</em> လုပ်ဖို့ လိုအပ်လို့ပါပဲ။ အောက်ပါ function က ဒါကို အတိအကျ လုပ်ဆောင်ပေးပြီး၊ summary sentences တွေကို newlines တွေနဲ့ ခွဲခြားဖို့ <code>nltk</code> က <code>sent_tokenize()</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">import</span> numpy <span class="hljs-keyword">as</span> np | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>): | |
| predictions, labels = eval_pred | |
| <span class="hljs-comment"># Generated summaries တွေကို text အဖြစ် Decode လုပ်ပါ</span> | |
| decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>) | |
| <span class="hljs-comment"># labels တွေထဲက -100 တွေကို ကျွန်တော်တို့ decode လုပ်လို့မရတာကြောင့် အစားထိုးပါ</span> | |
| labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id) | |
| <span class="hljs-comment"># Reference summaries တွေကို text အဖြစ် Decode လုပ်ပါ</span> | |
| decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>) | |
| <span class="hljs-comment"># ROUGE က sentence တိုင်းနောက်မှာ newline တစ်ခု လိုအပ်ပါတယ်</span> | |
| decoded_preds = [<span class="hljs-string">"\n"</span>.join(sent_tokenize(pred.strip())) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds] | |
| decoded_labels = [<span class="hljs-string">"\n"</span>.join(sent_tokenize(label.strip())) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels] | |
| <span class="hljs-comment"># ROUGE scores တွေကို တွက်ချက်ပါ</span> | |
| result = rouge_score.compute( | |
| predictions=decoded_preds, references=decoded_labels, use_stemmer=<span class="hljs-literal">True</span> | |
| ) | |
| <span class="hljs-comment"># Median scores တွေကို ထုတ်ယူပါ</span> | |
| result = {key: value.mid.fmeasure * <span class="hljs-number">100</span> <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> result.items()} | |
| <span class="hljs-keyword">return</span> {k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-armtiq">နောက်တစ်ဆင့်အနေနဲ့၊ ကျွန်တော်တို့ရဲ့ sequence-to-sequence task အတွက် data collator တစ်ခုကို သတ်မှတ်ဖို့ လိုပါတယ်။ mT5 က encoder-decoder Transformer model ဖြစ်တာကြောင့်၊ ကျွန်တော်တို့ရဲ့ batches တွေကို ပြင်ဆင်ရာမှာ သိမ်မွေ့မှုတစ်ခု ရှိပါတယ်၊ decoding လုပ်နေစဉ် labels တွေကို ညာဘက်သို့ တစ်နေရာရွှေ့ဖို့ လိုအပ်ပါတယ်။ ဒါက decoder က ယခင် ground truth labels တွေကိုသာ မြင်ရပြီး၊ လက်ရှိ ဒါမှမဟုတ် အနာဂတ် labels တွေကို မမြင်ရဖို့ သေချာစေဖို့အတွက် လိုအပ်ပါတယ်။ အဲဒါတွေက model က မှတ်မိဖို့ လွယ်ကူမှာဖြစ်ပါတယ်။ ဒါက <a href="/course/chapter7/6">causal language modeling</a> လို task တစ်ခုမှာ inputs တွေပေါ်မှာ masked self-attention ဘယ်လိုအသုံးပြုလဲဆိုတာနဲ့ ဆင်တူပါတယ်။</p> <p data-svelte-h="svelte-1bsi5t7">ကံကောင်းစွာနဲ့ပဲ၊ 🤗 Transformers က inputs တွေနဲ့ labels တွေကို dynamically pad လုပ်ပေးမယ့် <code>DataCollatorForSeq2Seq</code> collator တစ်ခုကို ပံ့ပိုးပေးပါတယ်။ ဒီ collator ကို instantiate လုပ်ဖို့၊ ကျွန်တော်တို့ <code>tokenizer</code> နဲ့ <code>model</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> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq | |
| data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-rayg7z">collator က ဥပမာအနည်းငယ်ကို ပေးလိုက်တဲ့အခါ ဘာတွေ ထုတ်လုပ်ပေးလဲဆိုတာ ကြည့်ရအောင်။ ပထမဆုံး၊ string တွေပါဝင်တဲ့ columns တွေကို ကျွန်တော်တို့ ဖယ်ရှားဖို့ လိုအပ်ပါတယ်။ ဘာလို့လဲဆိုတော့ collator က ဒီ elements တွေကို ဘယ်လို pad လုပ်ရမလဲဆိုတာ သိမှာ မဟုတ်လို့ပါပဲ။</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 -->tokenized_datasets = tokenized_datasets.remove_columns( | |
| books_dataset[<span class="hljs-string">"train"</span>].column_names | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-gjzzme">collator က <code>dict</code> တွေရဲ့ list ကို မျှော်လင့်ထားတာကြောင့် (dict တစ်ခုစီက dataset ထဲက single example ကို ကိုယ်စားပြုပါတယ်)၊ data ကို collator ကို မပေးပို့ခင် မျှော်လင့်ထားတဲ့ format အဖြစ် wrangle လုပ်ဖို့လည်း ကျွန်တော်တို့ လိုအပ်ပါတယ်။</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 -->features = [tokenized_datasets[<span class="hljs-string">"train"</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>)] | |
| data_collator(features)<!-- 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">'attention_mask'</span>: tensor([[<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, | |
| <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>], | |
| [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, | |
| <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]]), <span class="hljs-string">'input_ids'</span>: tensor([[ <span class="hljs-number">1494</span>, <span class="hljs-number">259</span>, <span class="hljs-number">8622</span>, <span class="hljs-number">390</span>, <span class="hljs-number">259</span>, <span class="hljs-number">262</span>, <span class="hljs-number">2316</span>, <span class="hljs-number">3435</span>, <span class="hljs-number">955</span>, | |
| <span class="hljs-number">772</span>, <span class="hljs-number">281</span>, <span class="hljs-number">772</span>, <span class="hljs-number">1617</span>, <span class="hljs-number">263</span>, <span class="hljs-number">305</span>, <span class="hljs-number">14701</span>, <span class="hljs-number">260</span>, <span class="hljs-number">1385</span>, | |
| <span class="hljs-number">3031</span>, <span class="hljs-number">259</span>, <span class="hljs-number">24146</span>, <span class="hljs-number">332</span>, <span class="hljs-number">1037</span>, <span class="hljs-number">259</span>, <span class="hljs-number">43906</span>, <span class="hljs-number">305</span>, <span class="hljs-number">336</span>, | |
| <span class="hljs-number">260</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>], | |
| [ <span class="hljs-number">259</span>, <span class="hljs-number">27531</span>, <span class="hljs-number">13483</span>, <span class="hljs-number">259</span>, <span class="hljs-number">7505</span>, <span class="hljs-number">260</span>, <span class="hljs-number">112240</span>, <span class="hljs-number">15192</span>, <span class="hljs-number">305</span>, | |
| <span class="hljs-number">53198</span>, <span class="hljs-number">276</span>, <span class="hljs-number">259</span>, <span class="hljs-number">74060</span>, <span class="hljs-number">263</span>, <span class="hljs-number">260</span>, <span class="hljs-number">459</span>, <span class="hljs-number">25640</span>, <span class="hljs-number">776</span>, | |
| <span class="hljs-number">2119</span>, <span class="hljs-number">336</span>, <span class="hljs-number">259</span>, <span class="hljs-number">2220</span>, <span class="hljs-number">259</span>, <span class="hljs-number">18896</span>, <span class="hljs-number">288</span>, <span class="hljs-number">4906</span>, <span class="hljs-number">288</span>, | |
| <span class="hljs-number">1037</span>, <span class="hljs-number">3931</span>, <span class="hljs-number">260</span>, <span class="hljs-number">7083</span>, <span class="hljs-number">101476</span>, <span class="hljs-number">1143</span>, <span class="hljs-number">260</span>, <span class="hljs-number">1</span>]]), <span class="hljs-string">'labels'</span>: tensor([[ <span class="hljs-number">7483</span>, <span class="hljs-number">259</span>, <span class="hljs-number">2364</span>, <span class="hljs-number">15695</span>, <span class="hljs-number">1</span>, -<span class="hljs-number">100</span>], | |
| [ <span class="hljs-number">259</span>, <span class="hljs-number">27531</span>, <span class="hljs-number">13483</span>, <span class="hljs-number">259</span>, <span class="hljs-number">7505</span>, <span class="hljs-number">1</span>]]), <span class="hljs-string">'decoder_input_ids'</span>: tensor([[ <span class="hljs-number">0</span>, <span class="hljs-number">7483</span>, <span class="hljs-number">259</span>, <span class="hljs-number">2364</span>, <span class="hljs-number">15695</span>, <span class="hljs-number">1</span>], | |
| [ <span class="hljs-number">0</span>, <span class="hljs-number">259</span>, <span class="hljs-number">27531</span>, <span class="hljs-number">13483</span>, <span class="hljs-number">259</span>, <span class="hljs-number">7505</span>]])}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1qg4zha">ဒီနေရာမှာ သတိထားရမယ့် အဓိကအချက်က ပထမဥပမာက ဒုတိယဥပမာထက် ပိုရှည်တာကြောင့်၊ ဒုတိယဥပမာရဲ့ <code>input_ids</code> နဲ့ <code>attention_mask</code> တွေကို ညာဘက်မှာ <code>[PAD]</code> token (၎င်းရဲ့ ID က <code>0</code> ဖြစ်ပါတယ်) နဲ့ padding လုပ်ထားပါတယ်။ အလားတူပဲ၊ <code>labels</code> တွေကို <code>-100</code> တွေနဲ့ padding လုပ်ထားတာကို တွေ့ရပါတယ်။ ဒါမှ padding tokens တွေကို loss function က လျစ်လျူရှုစေမှာပါ။ နောက်ဆုံးအနေနဲ့၊ <code>decoder_input_ids</code> အသစ်တစ်ခုကို ကျွန်တော်တို့ တွေ့မြင်နိုင်ပါတယ်။ ဒါက ပထမ entry မှာ <code>[PAD]</code> token တစ်ခု ထည့်သွင်းခြင်းဖြင့် labels တွေကို ညာဘက်သို့ ရွှေ့ထားပါတယ်။</p> <p data-svelte-h="svelte-1swemvg">ကျွန်တော်တို့ training လုပ်ဖို့ လိုအပ်တဲ့ ingredients အားလုံးကို နောက်ဆုံးတော့ ရရှိပါပြီ! အခု ကျွန်တော်တို့က trainer ကို standard arguments တွေနဲ့ instantiate လုပ်ဖို့ပဲ လိုအပ်ပါတယ်။</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> Seq2SeqTrainer | |
| trainer = Seq2SeqTrainer( | |
| model, | |
| args, | |
| train_dataset=tokenized_datasets[<span class="hljs-string">"train"</span>], | |
| eval_dataset=tokenized_datasets[<span class="hljs-string">"validation"</span>], | |
| data_collator=data_collator, | |
| tokenizer=tokenizer, | |
| compute_metrics=compute_metrics, | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-94sb6n">ပြီးရင် training run ကို စတင်ပါ။</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-xhbd82">training လုပ်နေစဉ်၊ epoch တိုင်းမှာ training loss ကျဆင်းပြီး ROUGE scores တိုးလာတာကို သင်တွေ့ရပါလိမ့်မယ်။ training ပြီးတာနဲ့ <code>Trainer.evaluate()</code> ကို run ခြင်းဖြင့် နောက်ဆုံး ROUGE scores တွေကို ကြည့်နိုင်ပါတယ်။</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.evaluate()<!-- 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">'eval_loss'</span>: <span class="hljs-number">3.028524398803711</span>, | |
| <span class="hljs-string">'eval_rouge1'</span>: <span class="hljs-number">16.9728</span>, | |
| <span class="hljs-string">'eval_rouge2'</span>: <span class="hljs-number">8.2969</span>, | |
| <span class="hljs-string">'eval_rougeL'</span>: <span class="hljs-number">16.8366</span>, | |
| <span class="hljs-string">'eval_rougeLsum'</span>: <span class="hljs-number">16.851</span>, | |
| <span class="hljs-string">'eval_gen_len'</span>: <span class="hljs-number">10.1597</span>, | |
| <span class="hljs-string">'eval_runtime'</span>: <span class="hljs-number">6.1054</span>, | |
| <span class="hljs-string">'eval_samples_per_second'</span>: <span class="hljs-number">38.982</span>, | |
| <span class="hljs-string">'eval_steps_per_second'</span>: <span class="hljs-number">4.914</span>}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-13vv419">scores တွေကနေ ကျွန်တော်တို့ model ဟာ ကျွန်တော်တို့ရဲ့ lead-3 baseline ကို ကောင်းကောင်းကျော်ဖြတ်နိုင်ခဲ့တာကို တွေ့မြင်နိုင်ပါတယ် — ကောင်းလိုက်တာ! နောက်ဆုံးလုပ်ဆောင်ရမယ့်အရာက model weights တွေကို Hub ကို push လုပ်ဖို့ပါပဲ၊ အောက်ပါအတိုင်း လုပ်ဆောင်ပါ။</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.push_to_hub(<span class="hljs-attribute">commit_message</span>=<span class="hljs-string">"Training complete"</span>, <span class="hljs-attribute">tags</span>=<span class="hljs-string">"summarization"</span>)<!-- 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">'https://huggingface.co/huggingface-course/mt5-small-finetuned-amazon-en-es/commit/aa0536b829b28e73e1e4b94b8a5aacec420d40e0'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-puwc7i">ဒါက checkpoint နဲ့ configuration files တွေကို <code>output_dir</code> မှာ သိမ်းဆည်းပေးပြီး၊ ဖိုင်အားလုံးကို Hub ကို upload လုပ်ပါလိမ့်မယ်။ <code>tags</code> argument ကို သတ်မှတ်ခြင်းဖြင့်၊ Hub ပေါ်က widget က mT5 architecture နဲ့ ဆက်စပ်နေတဲ့ default text generation pipeline အစား summarization pipeline အတွက် ဖြစ်နေဖို့လည်း ကျွန်တော်တို့ သေချာစေပါတယ် (model tags တွေအကြောင်း အသေးစိတ်အချက်အလက်တွေအတွက် <a href="https://huggingface.co/docs/hub/main#how-is-a-models-type-of-inference-api-and-widget-determined" rel="nofollow">🤗 Hub documentation</a> ကို ကြည့်ပါ)။ <code>trainer.push_to_hub()</code> ကနေ ထွက်လာတဲ့ output က Git commit hash ရဲ့ URL ဖြစ်တာကြောင့်၊ model repository မှာ ပြုလုပ်ခဲ့တဲ့ ပြောင်းလဲမှုတွေကို သင်အလွယ်တကူ မြင်နိုင်ပါလိမ့်မယ်!</p> <p data-svelte-h="svelte-1rijar8">ဒီအပိုင်းကို နိဂုံးချုပ်အနေနဲ့၊ 🤗 Accelerate က ပံ့ပိုးပေးတဲ့ low-level features တွေကို အသုံးပြုပြီး mT5 ကို ဘယ်လို fine-tune လုပ်နိုင်လဲဆိုတာ ကြည့်ရအောင်။</p> <h2 class="relative group"><a id="fine-tuning-mt5-with-accelerate" 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-mt5-with-accelerate"><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>🤗 Accelerate ဖြင့် mT5 ကို Fine-tuning လုပ်ခြင်း</span></h2> <p data-svelte-h="svelte-1pl9j4j">🤗 Accelerate ဖြင့် ကျွန်တော်တို့ model ကို fine-tuning လုပ်တာက <a href="/course/chapter3">Chapter 3</a> မှာ ကြုံတွေ့ခဲ့ရတဲ့ text classification ဥပမာနဲ့ အလွန်ဆင်တူပါတယ်။ အဓိကကွာခြားချက်တွေက training လုပ်နေစဉ် ကျွန်တော်တို့ summaries တွေကို ရှင်းရှင်းလင်းလင်း ထုတ်လုပ်ဖို့ လိုအပ်ပြီး ROUGE scores တွေကို ဘယ်လိုတွက်ချက်မလဲဆိုတာ သတ်မှတ်ဖို့ လိုအပ်မှာပါ (recall လုပ်ကြည့်ပါ၊ <code>Seq2SeqTrainer</code> က ကျွန်တော်တို့အတွက် generation ကို ဂရုစိုက်ပေးခဲ့ပါတယ်)။ 🤗 Accelerate ထဲမှာ ဒီလိုအပ်ချက်နှစ်ခုကို ဘယ်လို implement လုပ်နိုင်လဲဆိုတာ ကြည့်ရအောင်!</p> <h3 class="relative group"><a id="preparing-everything-for-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="#preparing-everything-for-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-1nqtbq8">ပထမဆုံး ကျွန်တော်တို့ လုပ်ရမှာက ကျွန်တော်တို့ splits တစ်ခုစီအတွက် <code>DataLoader</code> တစ်ခု ဖန်တီးဖို့ပါပဲ။ PyTorch dataloaders တွေက batches of tensors တွေကို မျှော်လင့်ထားတာကြောင့်၊ ကျွန်တော်တို့ datasets တွေမှာ format ကို <code>"torch"</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 -->tokenized_datasets.set_format(<span class="hljs-string">"torch"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-djbt29">အခု tensors တွေသာ ပါဝင်တဲ့ datasets တွေရပြီဆိုတော့၊ နောက်တစ်ဆင့်အနေနဲ့ <code>DataCollatorForSeq2Seq</code> ကို ထပ်မံ instantiate လုပ်ဖို့ပါပဲ။ ဒီအတွက် model ရဲ့ version အသစ်တစ်ခုကို ပေးဖို့ လိုအပ်တာကြောင့်၊ ကျွန်တော်တို့ cache ကနေ ဒါကို ထပ် load လုပ်ရအောင်။</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 -->model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fv0kb5">ပြီးရင် data collator ကို instantiate လုပ်ပြီး ဒါကို ကျွန်တော်တို့ dataloaders တွေကို သတ်မှတ်ဖို့ အသုံးပြုနိုင်ပါတယ်။</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> torch.utils.data <span class="hljs-keyword">import</span> DataLoader | |
| batch_size = <span class="hljs-number">8</span> | |
| train_dataloader = DataLoader( | |
| tokenized_datasets[<span class="hljs-string">"train"</span>], | |
| shuffle=<span class="hljs-literal">True</span>, | |
| collate_fn=data_collator, | |
| batch_size=batch_size, | |
| ) | |
| eval_dataloader = DataLoader( | |
| tokenized_datasets[<span class="hljs-string">"validation"</span>], collate_fn=data_collator, batch_size=batch_size | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1ey49fz">နောက်တစ်ဆင့်အနေနဲ့ အသုံးပြုချင်တဲ့ optimizer ကို သတ်မှတ်ဖို့ပါပဲ။ ကျွန်တော်တို့ရဲ့ အခြားဥပမာတွေမှာလိုပဲ၊ ပြဿနာအများစုအတွက် ကောင်းကောင်းအလုပ်လုပ်တဲ့ <code>AdamW</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> torch.optim <span class="hljs-keyword">import</span> AdamW | |
| optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1qtim2q">နောက်ဆုံးအနေနဲ့၊ ကျွန်တော်တို့ model၊ optimizer နဲ့ dataloaders တွေကို <code>accelerator.prepare()</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">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator | |
| accelerator = Accelerator() | |
| model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare( | |
| model, optimizer, train_dataloader, eval_dataloader | |
| )<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1cz7dar"><p>🚨 သင် TPU ပေါ်မှာ train လုပ်နေတယ်ဆိုရင်၊ အပေါ်က code အားလုံးကို dedicated training function တစ်ခုထဲကို ရွှေ့ဖို့ လိုပါလိမ့်မယ်။ အသေးစိတ်အချက်အလက်တွေအတွက် <a href="/course/chapter3">Chapter 3</a> ကို ကြည့်ပါ။</p></blockquote> <p data-svelte-h="svelte-1ff3ff1">အခု ကျွန်တော်တို့ objects တွေကို ပြင်ဆင်ပြီးပြီဆိုတော့၊ ကျန်ရှိတဲ့ လုပ်စရာသုံးခု ရှိပါသေးတယ်။</p> <ul data-svelte-h="svelte-1jj46g0"><li>Learning rate schedule ကို သတ်မှတ်ပါ။</li> <li>Evaluation အတွက် summaries တွေကို post-process လုပ်ဖို့ function တစ်ခုကို implement လုပ်ပါ။</li> <li>ကျွန်တော်တို့ model ကို push လုပ်နိုင်မယ့် Hub ပေါ်မှာ repository တစ်ခု ဖန်တီးပါ။</li></ul> <p data-svelte-h="svelte-16v3iqb">learning rate schedule အတွက်၊ ယခင်အပိုင်းတွေက standard linear schedule ကို ကျွန်တော်တို့ အသုံးပြုပါမယ်။</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> get_scheduler | |
| num_train_epochs = <span class="hljs-number">10</span> | |
| num_update_steps_per_epoch = <span class="hljs-built_in">len</span>(train_dataloader) | |
| num_training_steps = num_train_epochs * num_update_steps_per_epoch | |
| lr_scheduler = get_scheduler( | |
| <span class="hljs-string">"linear"</span>, | |
| optimizer=optimizer, | |
| num_warmup_steps=<span class="hljs-number">0</span>, | |
| num_training_steps=num_training_steps, | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1lnw9k2">Post-processing အတွက်၊ generated summaries တွေကို newlines တွေနဲ့ ခွဲထားတဲ့ sentences တွေအဖြစ် ခွဲထုတ်ပေးမယ့် function တစ်ခု လိုအပ်ပါတယ်။ ဒါက ROUGE metric မျှော်လင့်ထားတဲ့ format ဖြစ်ပြီး၊ အောက်ပါ code snippet နဲ့ ဒါကို အောင်မြင်အောင် လုပ်ဆောင်နိုင်ပါတယ်။</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_">postprocess_text</span>(<span class="hljs-params">preds, labels</span>): | |
| preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds] | |
| labels = [label.strip() <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels] | |
| <span class="hljs-comment"># ROUGE က sentence တိုင်းနောက်မှာ newline တစ်ခု လိုအပ်ပါတယ်</span> | |
| preds = [<span class="hljs-string">"\n"</span>.join(nltk.sent_tokenize(pred)) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds] | |
| labels = [<span class="hljs-string">"\n"</span>.join(nltk.sent_tokenize(label)) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels] | |
| <span class="hljs-keyword">return</span> preds, labels<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-xfuflc"><code>Seq2SeqTrainer</code> ရဲ့ <code>compute_metrics()</code> function ကို ဘယ်လိုသတ်မှတ်ခဲ့လဲဆိုတာ သင်မှတ်မိတယ်ဆိုရင် ဒါက သင့်အတွက် ရင်းနှီးနေမှာပါ။</p> <p data-svelte-h="svelte-14yj8py">နောက်ဆုံးအနေနဲ့၊ Hugging Face Hub ပေါ်မှာ model repository တစ်ခု ဖန်တီးဖို့ လိုအပ်ပါတယ်။ ဒီအတွက်၊ သင့်လျော်တဲ့ခေါင်းစဉ်ရှိတဲ့ 🤗 Hub library ကို ကျွန်တော်တို့ အသုံးပြုနိုင်ပါတယ်။ ကျွန်တော်တို့ repository အတွက် နာမည်တစ်ခု သတ်မှတ်ဖို့ပဲ လိုအပ်ပြီး၊ library မှာ repository ID ကို user profile နဲ့ ပေါင်းစပ်ဖို့ utility 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">from</span> huggingface_hub <span class="hljs-keyword">import</span> get_full_repo_name | |
| model_name = <span class="hljs-string">"test-bert-finetuned-squad-accelerate"</span> | |
| repo_name = get_full_repo_name(model_name) | |
| repo_name<!-- 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">'lewtun/mt5-finetuned-amazon-en-es-accelerate'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1yqeb1o">အခု ဒီ repository name ကို အသုံးပြုပြီး ကျွန်တော်တို့ရဲ့ results directory ထဲကို local version တစ်ခုကို clone လုပ်နိုင်ပါတယ်။ အဲဒီ directory က training artifacts တွေကို သိမ်းဆည်းထားပါလိမ့်မယ်။</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> huggingface_hub <span class="hljs-keyword">import</span> Repository | |
| output_dir = <span class="hljs-string">"results-mt5-finetuned-squad-accelerate"</span> | |
| repo = Repository(output_dir, clone_from=repo_name)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-q8mhpb">ဒါက training လုပ်နေစဉ် <code>repo.push_to_hub()</code> method ကို ခေါ်ခြင်းဖြင့် artifacts တွေကို Hub ကို ပြန် push လုပ်နိုင်စေပါလိမ့်မယ်! အခု ကျွန်တော်တို့ရဲ့ analysis ကို training loop ကို ရေးသားခြင်းဖြင့် နိဂုံးချုပ်လိုက်ရအောင်။</p> <h3 class="relative group"><a id="training-loop" 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-loop"><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 Loop</span></h3> <p data-svelte-h="svelte-bgogdr">Summarization အတွက် training loop က ကျွန်တော်တို့ ကြုံတွေ့ခဲ့ရတဲ့ အခြား 🤗 Accelerate ဥပမာတွေနဲ့ အတော်လေး ဆင်တူပြီး အကြမ်းဖျင်းအားဖြင့် အဓိကအဆင့်လေးဆင့် ခွဲထားပါတယ်။</p> <p data-svelte-h="svelte-1juxda8">၁။ epoch တစ်ခုစီအတွက် <code>train_dataloader</code> ထဲက ဥပမာအားလုံးကို iterate လုပ်ခြင်းဖြင့် model ကို train လုပ်ပါ။ | |
| ၂။ epoch တစ်ခုစီရဲ့ အဆုံးမှာ model summaries တွေ ထုတ်လုပ်ပါ။ ဒါက tokens တွေကို အရင်ထုတ်လုပ်ပြီး ပြီးရင် ၎င်းတို့ (နဲ့ reference summaries) တွေကို text အဖြစ် decode လုပ်ခြင်းဖြင့် လုပ်ဆောင်ပါတယ်။ | |
| ၃။ အစောပိုင်းက ကျွန်တော်တို့ တွေ့ခဲ့ရတဲ့ နည်းလမ်းတွေ တူတူကို အသုံးပြုပြီး ROUGE scores တွေကို တွက်ချက်ပါ။ | |
| ၄။ checkpoints တွေကို save လုပ်ပြီး အရာအားလုံးကို Hub ကို push လုပ်ပါ။ ဒီနေရာမှာ ကျွန်တော်တို့ <code>Repository</code> object ရဲ့ အသုံးဝင်တဲ့ <code>blocking=False</code> argument ကို အားကိုးပါတယ်။ ဒါက epoch တစ်ခုစီအတွက် checkpoints တွေကို <em>asynchronously</em> push လုပ်နိုင်စေပါတယ်။ ဒါက GB အရွယ်အစားရှိတဲ့ model နဲ့ ဆက်စပ်နေတဲ့ အနည်းငယ်နှေးကွေးတဲ့ upload ကို စောင့်စရာမလိုဘဲ training ကို ဆက်လက်လုပ်ဆောင်နိုင်စေပါတယ်။</p> <p data-svelte-h="svelte-d5of54">ဒီအဆင့်တွေကို အောက်ပါ code block မှာ တွေ့မြင်နိုင်ပါတယ်။</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> tqdm.auto <span class="hljs-keyword">import</span> tqdm | |
| <span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np | |
| progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps)) | |
| <span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_train_epochs): | |
| <span class="hljs-comment"># Training</span> | |
| model.train() | |
| <span class="hljs-keyword">for</span> step, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(train_dataloader): | |
| outputs = model(**batch) | |
| loss = outputs.loss | |
| accelerator.backward(loss) | |
| optimizer.step() | |
| lr_scheduler.step() | |
| optimizer.zero_grad() | |
| progress_bar.update(<span class="hljs-number">1</span>) | |
| <span class="hljs-comment"># Evaluation</span> | |
| model.<span class="hljs-built_in">eval</span>() | |
| <span class="hljs-keyword">for</span> step, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(eval_dataloader): | |
| <span class="hljs-keyword">with</span> torch.no_grad(): | |
| generated_tokens = accelerator.unwrap_model(model).generate( | |
| batch[<span class="hljs-string">"input_ids"</span>], | |
| attention_mask=batch[<span class="hljs-string">"attention_mask"</span>], | |
| ) | |
| generated_tokens = accelerator.pad_across_processes( | |
| generated_tokens, dim=<span class="hljs-number">1</span>, pad_index=tokenizer.pad_token_id | |
| ) | |
| labels = batch[<span class="hljs-string">"labels"</span>] | |
| <span class="hljs-comment"># အကယ်၍ ကျွန်တော်တို့ max length အထိ padding မလုပ်ခဲ့ရင်၊ labels တွေကိုလည်း pad လုပ်ဖို့ လိုအပ်ပါတယ်</span> | |
| labels = accelerator.pad_across_processes( | |
| batch[<span class="hljs-string">"labels"</span>], dim=<span class="hljs-number">1</span>, pad_index=tokenizer.pad_token_id | |
| ) | |
| generated_tokens = accelerator.gather(generated_tokens).cpu().numpy() | |
| labels = accelerator.gather(labels).cpu().numpy() | |
| <span class="hljs-comment"># labels တွေထဲက -100 တွေကို ကျွန်တော်တို့ decode လုပ်လို့မရတာကြောင့် အစားထိုးပါ</span> | |
| labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id) | |
| <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(generated_tokens, <span class="hljs-built_in">tuple</span>): | |
| generated_tokens = generated_tokens[<span class="hljs-number">0</span>] | |
| decoded_preds = tokenizer.batch_decode( | |
| generated_tokens, skip_special_tokens=<span class="hljs-literal">True</span> | |
| ) | |
| decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>) | |
| decoded_preds, decoded_labels = postprocess_text( | |
| decoded_preds, decoded_labels | |
| ) | |
| rouge_score.add_batch(predictions=decoded_preds, references=decoded_labels) | |
| <span class="hljs-comment"># Metrics တွေကို တွက်ချက်ပါ</span> | |
| result = rouge_score.compute() | |
| <span class="hljs-comment"># Median ROUGE scores တွေကို ထုတ်ယူပါ</span> | |
| result = {key: value.mid.fmeasure * <span class="hljs-number">100</span> <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> result.items()} | |
| result = {k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()} | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"Epoch <span class="hljs-subst">{epoch}</span>:"</span>, result) | |
| <span class="hljs-comment"># Save လုပ်ပြီး upload လုပ်ပါ</span> | |
| accelerator.wait_for_everyone() | |
| unwrapped_model = accelerator.unwrap_model(model) | |
| unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save) | |
| <span class="hljs-keyword">if</span> accelerator.is_main_process: | |
| tokenizer.save_pretrained(output_dir) | |
| repo.push_to_hub( | |
| commit_message=<span class="hljs-string">f"Training in progress epoch <span class="hljs-subst">{epoch}</span>"</span>, blocking=<span class="hljs-literal">False</span> | |
| )<!-- 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 -->Epoch <span class="hljs-number">0</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">5.6351</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">1.1625</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">5.4866</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">5.5005</span>} | |
| Epoch <span class="hljs-number">1</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">9.8646</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">3.4106</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">9.9439</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">9.9306</span>} | |
| Epoch <span class="hljs-number">2</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">11.0872</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">3.3273</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">11.0508</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">10.9468</span>} | |
| Epoch <span class="hljs-number">3</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">11.8587</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">4.8167</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">11.7986</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">11.7518</span>} | |
| Epoch <span class="hljs-number">4</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">12.9842</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">5.5887</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">12.7546</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">12.7029</span>} | |
| Epoch <span class="hljs-number">5</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">13.4628</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">6.4598</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">13.312</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">13.2913</span>} | |
| Epoch <span class="hljs-number">6</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">12.9131</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">5.8914</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">12.6896</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">12.5701</span>} | |
| Epoch <span class="hljs-number">7</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">13.3079</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">6.2994</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">13.1536</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">13.1194</span>} | |
| Epoch <span class="hljs-number">8</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">13.96</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">6.5998</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">13.9123</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">13.7744</span>} | |
| Epoch <span class="hljs-number">9</span>: {<span class="hljs-string">'rouge1'</span>: <span class="hljs-number">14.1192</span>, <span class="hljs-string">'rouge2'</span>: <span class="hljs-number">7.0059</span>, <span class="hljs-string">'rougeL'</span>: <span class="hljs-number">14.1172</span>, <span class="hljs-string">'rougeLsum'</span>: <span class="hljs-number">13.9509</span>}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-qme28l">ဒါပါပဲ! ဒါကို run လိုက်တာနဲ့၊ <code>Trainer</code> နဲ့ ကျွန်တော်တို့ ရရှိခဲ့တဲ့ ရလဒ်တွေနဲ့ အတော်လေး ဆင်တူတဲ့ model နဲ့ results တွေ သင်ရရှိပါလိမ့်မယ်။</p> <h2 class="relative group"><a id="using-your-fine-tuned-model" 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="#using-your-fine-tuned-model"><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>သင် Fine-tuned လုပ်ထားသော Model ကို အသုံးပြုခြင်း</span></h2> <p data-svelte-h="svelte-je4z3f">Model ကို Hub ကို push လုပ်ပြီးတာနဲ့၊ inference widget ဒါမှမဟုတ် <code>pipeline</code> object ကို အသုံးပြုပြီး ဒါနဲ့ ကစားနိုင်ပါတယ်၊ အောက်ပါအတိုင်းပါ…</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> pipeline | |
| hub_model_id = <span class="hljs-string">"huggingface-course/mt5-small-finetuned-amazon-en-es"</span> | |
| summarizer = pipeline(<span class="hljs-string">"summarization"</span>, model=hub_model_id)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-9ojfzt">test set (model က မမြင်ဖူးသေးသော) က ဥပမာအချို့ကို ကျွန်တော်တို့ရဲ့ pipeline ကို ပေးပို့ခြင်းဖြင့် summaries တွေရဲ့ အရည်အသွေးကို ခံစားကြည့်နိုင်ပါတယ်။ ပထမဆုံး review၊ title နဲ့ generated summary တွေကို အတူတကွ ပြသဖို့ ရိုးရှင်းတဲ့ function တစ်ခုကို implement လုပ်ရအောင်။</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_">print_summary</span>(<span class="hljs-params">idx</span>): | |
| review = books_dataset[<span class="hljs-string">"test"</span>][idx][<span class="hljs-string">"review_body"</span>] | |
| title = books_dataset[<span class="hljs-string">"test"</span>][idx][<span class="hljs-string">"review_title"</span>] | |
| summary = summarizer(books_dataset[<span class="hljs-string">"test"</span>][idx][<span class="hljs-string">"review_body"</span>])[<span class="hljs-number">0</span>][<span class="hljs-string">"summary_text"</span>] | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"'>>> Review: <span class="hljs-subst">{review}</span>'"</span>) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"\n'>>> Title: <span class="hljs-subst">{title}</span>'"</span>) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"\n'>>> Summary: <span class="hljs-subst">{summary}</span>'"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-10dtjen">ကျွန်တော်တို့ ရရှိတဲ့ English ဥပမာတွေထဲက တစ်ခုကို ကြည့်ရအောင်…</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 -->print_summary(<span class="hljs-number">100</span>)<!-- 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">'>>> Review: Nothing special at all about this product... the book is too small and stiff and hard to write in. The huge sticker on the back doesn’t come off and looks super tacky. I would not purchase this again. I could have just bought a journal from the dollar store and it would be basically the same thing. It’s also really expensive for what it is.'</span> | |
| <span class="hljs-string">'>>> Title: Not impressed at all... buy something else'</span> | |
| <span class="hljs-string">'>>> Summary: Nothing special at all about this product'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1s8cyc5">ဒါက သိပ်မဆိုးပါဘူး! ကျွန်တော်တို့ model ဟာ review ရဲ့ အစိတ်အပိုင်းတွေကို စကားလုံးအသစ်တွေနဲ့ ဖြည့်စွက်ခြင်းဖြင့် <em>abstractive</em> summarization ကို တကယ်လုပ်ဆောင်နိုင်ခဲ့တာကို တွေ့မြင်နိုင်ပါတယ်။ ပြီးတော့ ကျွန်တော်တို့ model ရဲ့ အမိုက်ဆုံး ကဏ္ဍကတော့ ဒါက bilingual ဖြစ်တာကြောင့် Spanish reviews တွေကိုလည်း summaries တွေ ထုတ်လုပ်နိုင်ပါတယ်။</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 -->print_summary(<span class="hljs-number">0</span>)<!-- 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">'>>> Review: Es una trilogia que se hace muy facil de leer. Me ha gustado, no me esperaba el final para nada'</span> | |
| <span class="hljs-string">'>>> Title: Buena literatura para adolescentes'</span> | |
| <span class="hljs-string">'>>> Summary: Muy facil de leer'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1t0k411">summary ကို English လို “Very easy to read” လို့ ဘာသာပြန်နိုင်ပြီး၊ ဒီကိစ္စမှာ review ကနေ တိုက်ရိုက်ထုတ်ယူထားတာကို ကျွန်တော်တို့ တွေ့မြင်နိုင်ပါတယ်။ သို့သော်လည်း၊ ဒါက mT5 model ရဲ့ versatility ကို ပြသပြီး multilingual corpus နဲ့ အလုပ်လုပ်တာ ဘယ်လိုလဲဆိုတာကို သင့်ကို ခံစားကြည့်ခွင့် ပေးခဲ့ပါတယ်။</p> <p data-svelte-h="svelte-11e0s56">နောက်တစ်ဆင့်အနေနဲ့၊ အနည်းငယ် ပိုရှုပ်ထွေးတဲ့ task တစ်ခုကို ကျွန်တော်တို့ အာရုံစိုက်ပါမယ်၊ language model တစ်ခုကို အစကနေ train လုပ်တာပါ။</p> <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-1y7lsoh"><li><strong>Transformer Models</strong>: Natural Language Processing (NLP) မှာ အောင်မြင်မှုများစွာရရှိခဲ့တဲ့ deep learning architecture တစ်မျိုးပါ။</li> <li><strong>Text Summarization</strong>: ရှည်လျားသော စာသားတစ်ခုကို အဓိကအချက်အလက်များပါဝင်သည့် ပိုတိုတောင်းသော version တစ်ခုအဖြစ် ပြောင်းလဲခြင်း။</li> <li><strong>NLP Tasks</strong>: ကွန်ပျူတာတွေ လူသားဘာသာစကားကို နားလည်၊ အဓိပ္ပာယ်ဖော်ပြီး၊ ဖန်တီးနိုင်အောင် လုပ်ဆောင်ပေးတဲ့ အလုပ်တွေ။</li> <li><strong>Coherent Text</strong>: အဓိပ္ပာယ်ပြည့်စုံပြီး စနစ်တကျရှိသော စာသား။</li> <li><strong>Domain Experts</strong>: သီးခြားနယ်ပယ်တစ်ခုတွင် ကျွမ်းကျင်သူများ။</li> <li><strong>Hugging Face Hub</strong>: AI မော်ဒယ်တွေ၊ datasets တွေနဲ့ demo တွေကို အခြားသူတွေနဲ့ မျှဝေဖို့၊ ရှာဖွေဖို့နဲ့ ပြန်လည်အသုံးပြုဖို့အတွက် အွန်လိုင်း platform တစ်ခု ဖြစ်ပါတယ်။</li> <li><strong>Pipeline Tag</strong>: Hugging Face Hub တွင် models များကို pipeline အမျိုးအစားအလိုက် စစ်ထုတ်ရန် အသုံးပြုသော tag။</li> <li><strong>Bilingual Model</strong>: ဘာသာစကားနှစ်မျိုး (ဤနေရာတွင် အင်္ဂလိပ်နှင့် စပိန်) ဖြင့် လုပ်ဆောင်နိုင်သော model။</li> <li><strong>Customer Reviews</strong>: ထုတ်ကုန်များ သို့မဟုတ် ဝန်ဆောင်မှုများနှင့် ပတ်သက်သော သုံးစွဲသူများ၏ ထင်မြင်ယူဆချက်များ။</li> <li><strong>Corpus</strong>: စာသား (သို့မဟုတ် အခြားဒေတာ) အစုအဝေးကြီးတစ်ခု။</li> <li><strong>Multilingual Amazon Reviews Corpus</strong>: Amazon ထုတ်ကုန် reviews များ ပါဝင်သည့် ဘာသာစကားမျိုးစုံသုံး dataset။</li> <li><strong>Multilingual Classifiers</strong>: ဘာသာစကားမျိုးစုံရှိ စာသားများကို အမျိုးအစားခွဲခြားနိုင်သော model များ။</li> <li><strong>Benchmark</strong>: Model များ၏ စွမ်းဆောင်ရည်ကို တိုင်းတာရန်အတွက် စံသတ်မှတ်ထားသော datasets နှင့် metrics များ။</li> <li><strong>Target Summaries</strong>: Model က ထုတ်လုပ်ရန် ရည်ရွယ်ထားသော အနှစ်ချုပ်စာသားများ (ဤနေရာတွင် review titles များ)။</li> <li><strong>Subsets</strong>: ပိုကြီးသော dataset တစ်ခုမှ ရွေးထုတ်ထားသော အစိတ်အပိုင်းများ။</li> <li><strong><code>load_dataset()</code> Function</strong>: Hugging Face Datasets library မှ dataset များကို download လုပ်ပြီး cache လုပ်ရန် အသုံးပြုသော function။</li> <li><strong><code>DatasetDict</code> Object</strong>: Training set, validation set, နှင့် test set ကဲ့သို့သော dataset အများအပြားကို dictionary ပုံစံဖြင့် သိမ်းဆည်းထားသော object။</li> <li><strong><code>train</code> Split</strong>: Model ကို လေ့ကျင့်ရန်အတွက် အသုံးပြုသော dataset အပိုင်း။</li> <li><strong><code>validation</code> Split</strong>: Training လုပ်နေစဉ် model ၏ စွမ်းဆောင်ရည်ကို အကဲဖြတ်ရန် အသုံးပြုသော dataset အပိုင်း။</li> <li><strong><code>test</code> Split</strong>: Model ၏ နောက်ဆုံး စွမ်းဆောင်ရည်ကို တိုင်းတာရန် အသုံးပြုသော dataset အပိုင်း။</li> <li><strong><code>review_body</code> Column</strong>: review ၏ အဓိက စာသားပါဝင်သော column။</li> <li><strong><code>review_title</code> Column</strong>: review ၏ ခေါင်းစဉ်ပါဝင်သော column။</li> <li><strong>Random Sample</strong>: dataset တစ်ခုမှ ကျပန်းရွေးချယ်ထားသော elements များ။</li> <li><strong><code>Dataset.shuffle()</code> Method</strong>: dataset အတွင်းရှိ elements များကို ကျပန်းရောနှော (shuffle) ရန် အသုံးပြုသော method။</li> <li><strong><code>Dataset.select()</code> Method</strong>: dataset ၏ သီးခြား elements များကို index များဖြင့် ရွေးထုတ်ရန် အသုံးပြုသော method။</li> <li><strong>Random Seed</strong>: ကျပန်းနံပါတ်များ ထုတ်လုပ်ခြင်းကို ထိန်းချုပ်ရန် အသုံးပြုသော ကနဦးတန်ဖိုး။</li> <li><strong>Overfit</strong>: Model တစ်ခုသည် training data ကို ကောင်းမွန်စွာ သင်ယူထားသော်လည်း မမြင်ဖူးသော data အပေါ်တွင် စွမ်းဆောင်ရည် နည်းပါးခြင်း။</li> <li><strong><code>pandas.DataFrame</code></strong>: Pandas library ၏ data structure တစ်ခုဖြစ်ပြီး tabular data များကို သိမ်းဆည်းရန် အသုံးပြုသည်။</li> <li><strong><code>value_counts()</code> Method</strong>: DataFrame column တစ်ခုအတွင်းရှိ ထူးခြားသော တန်ဖိုးတစ်ခုစီ၏ အရေအတွက်ကို ရေတွက်သော Pandas method။</li> <li><strong>Product Category</strong>: ထုတ်ကုန်များ၏ အမျိုးအစား။</li> <li><strong><code>Dataset.filter()</code> Function</strong>: 🤗 Datasets library မှာ ပါဝင်တဲ့ method တစ်ခုဖြစ်ပြီး သတ်မှတ်ထားသော အခြေအနေများနှင့် ကိုက်ညီသော ဒေတာများကိုသာ dataset မှ ရွေးထုတ်ရန် အသုံးပြုသည်။</li> <li><strong>Heuristic</strong>: ပြဿနာတစ်ခုကို ဖြေရှင်းရန်အတွက် လက်တွေ့ကျသော သို့မဟုတ် rule-of-thumb နည်းလမ်း။</li> <li><strong>Whitespace</strong>: စာသားများအတွင်းရှိ နေရာလွတ်များ (space, tab, newline)။</li> <li><strong><code>split()</code> Method</strong>: string တစ်ခုကို သတ်မှတ်ထားသော delimiter (ဥပမာ- whitespace) ဖြင့် ပိုင်းခြားပြီး list တစ်ခုအဖြစ် ပြန်ပေးသော Python string method။</li> <li><strong><code>concatenate_datasets()</code> Function</strong>: 🤗 Datasets library မှ <code>Dataset</code> objects နှစ်ခု သို့မဟုတ် နှစ်ခုထက်ပိုသော objects များကို ပေါင်းစပ်ရန် အသုံးပြုသော function။</li> <li><strong>Skewed</strong>: data ၏ ဖြန့်ဝေမှု (distribution) သည် တစ်ဖက်သို့ စောင်းနေခြင်း။</li> <li><strong>Encoder-Decoder Architecture</strong>: Transformer architecture တစ်မျိုးဖြစ်ပြီး input sequence ကို encode လုပ်ရန် encoder နှင့် output sequence ကို decode လုပ်ရန် decoder နှစ်ခုပါဝင်သည်။</li> <li><strong>GPT Family of Models</strong>: OpenAI မှ ထုတ်လုပ်ထားသော Generative Pretrained Transformer (GPT) models များ။ auto-regressive language models များဖြစ်သည်။</li> <li><strong>Few-shot Settings</strong>: လေ့ကျင့်မှုအတွက် data ဥပမာအနည်းငယ်သာ ရရှိနိုင်သော အခြေအနေ။</li> <li><strong>GPT-2</strong>: auto-regressive language model တစ်ခု။</li> <li><strong>Auto-regressive Language Model</strong>: ယခင် token များကို အခြေခံ၍ နောက် token ကို ခန့်မှန်းသော language model။</li> <li><strong>TL;DR (Too Long; Didn’t Read)</strong>: ရှည်လျားသော စာသားတစ်ခု၏ အနှစ်ချုပ်ကို ဖော်ပြရန် အင်တာနက်တွင် အသုံးပြုသော အတိုကောက်။</li> <li><strong>PEGASUS</strong>: Masked sentences များကို ခန့်မှန်းခြင်းဖြင့် pretraining လုပ်ထားသော summarization model။</li> <li><strong>T5 (Text-to-Text Transfer Transformer)</strong>: NLP tasks အားလုံးကို text-to-text format ဖြင့် ကိုင်တွယ်သော universal Transformer architecture။</li> <li><strong><code>summarize: ARTICLE</code></strong>: T5 model တွင် summarization task အတွက် အသုံးပြုသော prompt prefix format။</li> <li><strong>mT5</strong>: T5 model ၏ multilingual version။</li> <li><strong>Multilingual Common Crawl Corpus (mC4)</strong>: ဘာသာစကားမျိုးစုံဖြင့် အင်တာနက်မှ စုဆောင်းထားသော large-scale corpus။</li> <li><strong>BART</strong>: Encoder-decoder architecture ပါဝင်သော Transformer model တစ်မျိုးဖြစ်ပြီး corrupted input များကို reconstruct လုပ်ရန် လေ့ကျင့်ထားသည်။</li> <li><strong>mBART-50</strong>: BART model ၏ multilingual version။</li> <li><strong>Monolingual</strong>: ဘာသာစကားတစ်ခုတည်းဖြင့်သာ လုပ်ဆောင်နိုင်သော။</li> <li><strong>High-resource Language</strong>: ဒေတာအမြောက်အမြားနှင့် ကိရိယာများစွာ ရရှိနိုင်သော ဘာသာစကား။</li> <li><strong>Jointly Trained</strong>: မော်ဒယ်တစ်ခုကို ဒေတာအမျိုးအစားမျိုးစုံ သို့မဟုတ် ဘာသာစကားမျိုးစုံဖြင့် တစ်ပြိုင်နက်တည်း လေ့ကျင့်ခြင်း။</li> <li><strong>Prefix</strong>: စာသား၏ အစပိုင်းတွင် ထည့်သွင်းထားသော စကားလုံး သို့မဟုတ် စာကြောင်း။</li> <li><strong>Condition</strong>: Model ၏ output ကို ထိန်းချုပ်ခြင်း သို့မဟုတ် သတ်မှတ်ခြင်း။</li> <li><strong>Versatile</strong>: ကိစ္စရပ်မျိုးစုံတွင် အသုံးပြုနိုင်သော။</li> <li><strong>Tokenize</strong>: စာသား (သို့မဟုတ် အခြားဒေတာ) ကို AI မော်ဒယ်များ စီမံဆောင်ရွက်နိုင်ရန် tokens တွေအဖြစ် ပိုင်းခြားပေးသည့် လုပ်ငန်းစဉ်။</li> <li><strong>Encode</strong>: ဒေတာများကို ဂဏန်းဆိုင်ရာ ကိုယ်စားပြုမှုအဖြစ် ပြောင်းလဲခြင်း။</li> <li><strong><code>AutoTokenizer</code></strong>: Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တစ်ခုဖြစ်ပြီး မော်ဒယ်အမည်ကို အသုံးပြုပြီး သက်ဆိုင်ရာ tokenizer ကို အလိုအလျောက် load လုပ်ပေးသည်။</li> <li><strong><code>mt5-small</code></strong>: mT5 model ၏ small version အတွက် checkpoint identifier။</li> <li><strong>Checkpoint</strong>: မော်ဒယ်၏ weights များနှင့် အခြားဖွဲ့စည်းပုံများ (configuration) ကို သတ်မှတ်ထားသော အချိန်တစ်ခုတွင် သိမ်းဆည်းထားခြင်း။</li> <li><strong>Debug</strong>: code ထဲက အမှားတွေကို ရှာဖွေပြီး ပြင်ဆင်ခြင်း။</li> <li><strong>Iterate</strong>: ပြဿနာတစ်ခုကို ဖြေရှင်းရန်အတွက် အဆင့်များစွာကို ထပ်ခါတလဲလဲ လုပ်ဆောင်ခြင်း။</li> <li><strong>End-to-end Workflow</strong>: အစမှအဆုံးအထိ ပြည့်စုံသော လုပ်ငန်းစီးဆင်းမှု။</li> <li><strong>Scale Up</strong>: Model ၏ အရွယ်အစား သို့မဟုတ် training data ပမာဏကို တိုးမြှင့်ခြင်း။</li> <li><strong><code>input_ids</code></strong>: Tokenizer မှ ထုတ်ပေးသော tokens တစ်ခုစီ၏ ထူးခြားသော ဂဏန်းဆိုင်ရာ ID များ။</li> <li><strong><code>attention_mask</code></strong>: မော်ဒယ်ကို အာရုံစိုက်သင့်သည့် tokens များနှင့် လျစ်လျူရှုသင့်သည့် (padding) tokens များကို ခွဲခြားပေးသည့် binary mask။</li> <li><strong>Decode</strong>: ဂဏန်းဆိုင်ရာ ကိုယ်စားပြုမှု (ဥပမာ- input IDs) ကို လူသားဖတ်နိုင်သော စာသားအဖြစ် ပြန်ပြောင်းခြင်း။</li> <li><strong><code>convert_ids_to_tokens()</code> Function</strong>: input IDs များကို tokens များအဖြစ် ပြန်ပြောင်းပေးသော tokenizer method။</li> <li><strong>Unicode Character <code></code></strong>: SentencePiece tokenizer တွင် word piece ၏ အစကို ဖော်ပြရန် အသုံးပြုသော အထူး character။</li> <li><strong>End-of-sequence Token <code></s></code></strong>: Sequence တစ်ခု၏ အဆုံးကို ဖော်ပြသော special token။</li> <li><strong>SentencePiece Tokenizer</strong>: Google မှ ဖန်တီးထားသော subword tokenizer တစ်ခုဖြစ်ပြီး input text ကို pre-tokenize လုပ်ရန် မလိုအပ်ပါ။</li> <li><strong>Unigram Segmentation Algorithm</strong>: subword tokenization algorithm တစ်မျိုး။</li> <li><strong>Agnostic</strong>: သီးခြားအချက်အလက်တစ်ခုကို ဂရုမစိုက်ခြင်း သို့မဟုတ် မှီခိုခြင်းမရှိခြင်း။</li> <li><strong>Accents</strong>: ဘာသာစကားများတွင် စကားလုံးများအပေါ်တွင် အသုံးပြုသော အသံထွက်ပြောင်းလဲမှုများ။</li> <li><strong>Punctuation</strong>: စာသားများတွင် အသုံးပြုသော သတ်ပုံအမှတ်အသားများ (ဥပမာ- comma, period, question mark)။</li> <li><strong>Whitespace Characters</strong>: နေရာလွတ် (space, tab, newline)။</li> <li><strong>Maximum Context Size</strong>: Model တစ်ခုက တစ်ပြိုင်နက်တည်း လုပ်ဆောင်နိုင်သော အများဆုံး tokens အရေအတွက်။</li> <li><strong>Truncation</strong>: input sequence ၏ အရှည်ကို model ၏ maximum context size သို့ လျှော့ချခြင်း။</li> <li><strong><code>text_target</code> Argument</strong>: tokenizer တွင် label text များကို input text နှင့် ပြိုင်တူ tokenize လုပ်ရန် အသုံးပြုသော argument။</li> <li><strong><code>max_input_length</code></strong>: Input sequence အတွက် သတ်မှတ်ထားသော အများဆုံး tokens အရေအတွက်။</li> <li><strong><code>max_target_length</code></strong>: Target (label) sequence အတွက် သတ်မှတ်ထားသော အများဆုံး tokens အရေအတွက်။</li> <li><strong><code>preprocess_function()</code></strong>: data ကို preprocessing လုပ်ရန်အတွက် သတ်မှတ်ထားသော function။</li> <li><strong><code>Dataset.map()</code> Function</strong>: 🤗 Datasets library မှာ ပါဝင်တဲ့ method တစ်ခုဖြစ်ပြီး dataset ရဲ့ element တစ်ခုစီ ဒါမှမဟုတ် batch တစ်ခုစီပေါ်မှာ function တစ်ခုကို အသုံးပြုနိုင်စေသည်။</li> <li><strong><code>batched=True</code></strong>: <code>map()</code> method မှာ အသုံးပြုသော argument တစ်ခုဖြစ်ပြီး function ကို dataset ရဲ့ element အများအပြားပေါ်မှာ တစ်ပြိုင်နက်တည်း အသုံးပြုစေသည်။</li> <li><strong>Multithreading Capabilities</strong>: Program တစ်ခု၏ threads များစွာကို တစ်ပြိုင်နက်တည်း လုပ်ဆောင်နိုင်စွမ်း။</li> <li><strong>ROUGE Score (Recall-Oriented Understudy for Gisting Evaluation)</strong>: generated summary တစ်ခုကို reference summaries များနှင့် နှိုင်းယှဉ်ခြင်းဖြင့် text summarization model များ၏ စွမ်းဆောင်ရည်ကို တိုင်းတာသော metric။</li> <li><strong>Text Generation Tasks</strong>: AI model များမှ စာသားအသစ်များ ထုတ်လုပ်ခြင်းနှင့် သက်ဆိုင်သော လုပ်ငန်းများ။</li> <li><strong>Exact Match</strong>: စာသားနှစ်ခု သို့မဟုတ် စကားလုံးနှစ်ခု တိတိကျကျ တူညီခြင်း။</li> <li><strong>Precision</strong>: generated summary ထဲက ဘယ်လောက်အတိုင်းအတာအထိ relevant ဖြစ်လဲဆိုတာကို တိုင်းတာသော metric။</li> <li><strong>Recall</strong>: reference summary ရဲ့ ဘယ်လောက်အတိုင်းအတာအထိ generated summary က ဖမ်းယူနိုင်လဲဆိုတာကို တိုင်းတာသော metric။</li> <li><strong>F1-score</strong>: Precision နှင့် Recall တို့၏ harmonic mean ကို တွက်ချက်သော metric။</li> <li><strong><code>rouge_score</code> Package</strong>: ROUGE score ကို တွက်ချက်ရန်အတွက် Python package။</li> <li><strong><code>evaluate</code> Library</strong>: Hugging Face မှ metrics များကို load လုပ်ရန်နှင့် တွက်ချက်ရန်အတွက် library။</li> <li><strong><code>evaluate.load("rouge")</code></strong>: ROUGE metric ကို load လုပ်ရန် command။</li> <li><strong><code>rouge_score.compute()</code> Function</strong>: ROUGE scores များကို တွက်ချက်ရန် function။</li> <li><strong>Confidence Intervals</strong>: parameter တစ်ခု၏ ဖြစ်နိုင်ခြေတန်ဖိုးများ ပါဝင်နိုင်သော အတိုင်းအတာတစ်ခု။</li> <li><strong><code>low</code>, <code>mid</code>, <code>high</code> Attributes</strong>: Confidence interval ၏ အနိမ့်ဆုံး၊ အလယ်အလတ်၊ အမြင့်ဆုံး တန်ဖိုးများ။</li> <li><strong>Text Granularity</strong>: စာသားကို ခွဲခြမ်းစိတ်ဖြာသည့် အဆင့် (ဥပမာ- စကားလုံးများ၊ bigrams, sentences)။</li> <li><strong>Unigrams</strong>: စာသားတစ်ခုမှ တစ်လုံးချင်းစီသော စကားလုံးများ။</li> <li><strong>Bigrams</strong>: စာသားတစ်ခုမှ စကားလုံးအတွဲများ။</li> <li><strong><code>rougeL</code></strong>: Longest Common Subsequence (LCS) ကို အခြေခံ၍ တွက်ချက်သော ROUGE score။ sentence တစ်ခုစီ၏ average LCS ကို တိုင်းတာသည်။</li> <li><strong><code>rougeLsum</code></strong>: <code>rougeL</code> နှင့် ဆင်တူသော်လည်း summary တစ်ခုလုံး၏ LCS ကို တိုင်းတာသည်။</li> <li><strong>Longest Common Substrings</strong>: စာသားနှစ်ခုကြားရှိ အရှည်ဆုံး တူညီသော စာသားအပိုင်းအစ။</li> <li><strong>Baseline</strong>: Model ၏ စွမ်းဆောင်ရည်ကို နှိုင်းယှဉ်ရန်အတွက် အသုံးပြုသော ရိုးရှင်းသော သို့မဟုတ် အခြေခံ model။</li> <li><strong>Lead-3 Baseline</strong>: Text summarization တွင် article တစ်ခု၏ ပထမဆုံး sentences သုံးခုကို summary အဖြစ် ယူသော baseline။</li> <li><strong><code>nltk</code> Library (Natural Language Toolkit)</strong>: Python အတွက် NLP လုပ်ငန်းများအတွက် ကိရိယာများနှင့် library များ စုစည်းမှု။</li> <li><strong><code>punkt</code> (NLTK Tokenizer Model)</strong>: <code>nltk</code> library အတွင်းရှိ sentence tokenizer အတွက် training data။</li> <li><strong><code>sent_tokenize()</code> Function</strong>: <code>nltk</code> မှ စာသားတစ်ခုကို sentences များအဖြစ် ပိုင်းခြားပေးသော function။</li> <li><strong><code>three_sentence_summary()</code> Function</strong>: စာသားတစ်ခုမှ ပထမဆုံး sentences သုံးခုကို ထုတ်ယူရန် သတ်မှတ်ထားသော function။</li> <li><strong><code>evaluate_baseline()</code> Function</strong>: baseline model ၏ စွမ်းဆောင်ရည်ကို ROUGE metric ဖြင့် အကဲဖြတ်ရန် function။</li> <li><strong><code>pandas</code></strong>: Python programming language အတွက် data analysis နှင့် manipulation အတွက် အသုံးပြုသော open-source library။</li> <li><strong><code>round()</code> Function</strong>: နံပါတ်တစ်ခုကို သတ်မှတ်ထားသော ဒသမနေရာအထိ ချုံ့ရန် Python function။</li> <li><strong>Skewed</strong>: data ၏ ဖြန့်ဝေမှု (distribution) သည် တစ်ဖက်သို့ စောင်းနေခြင်း။</li> <li><strong><code>AutoModelForSeq2SeqLM</code></strong>: Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တစ်ခုဖြစ်ပြီး sequence-to-sequence language modeling (ဥပမာ- summarization, translation) အတွက် model တစ်ခုကို အလိုအလျောက် load လုပ်ပေးသည်။</li> <li><strong>Sequence-to-sequence Task</strong>: input sequence တစ်ခုမှ output sequence တစ်ခုကို ထုတ်လုပ်သော task အမျိုးအစား။</li> <li><strong><code>TFAutoModelForSeq2SeqLM</code></strong>: TensorFlow framework အတွက် <code>AutoModelForSeq2SeqLM</code> နှင့် တူညီသော လုပ်ဆောင်ချက်များရှိသည်။</li> <li><strong>Downstream Task</strong>: Pretrained model တစ်ခုကို fine-tune လုပ်ရန် အသုံးပြုသော သီးခြားလုပ်ငန်း။</li> <li><strong>Randomly Initialized Network</strong>: အစပိုင်းတွင် weights များကို ကျပန်းတန်ဖိုးများဖြင့် သတ်မှတ်ထားသော neural network။</li> <li><strong><code>notebook_login()</code> Function</strong>: Jupyter/Colab Notebooks များတွင် Hugging Face Hub သို့ login ဝင်ရန် အသုံးပြုသော function။</li> <li><strong>Credentials</strong>: အသုံးပြုသူအမည်နှင့် စကားဝှက်ကဲ့သို့ အကောင့်ဝင်ရန်အတွက် အချက်အလက်များ။</li> <li><strong><code>huggingface-cli login</code></strong>: Hugging Face CLI (Command Line Interface) မှ Hugging Face Hub သို့ login ဝင်ရန် အသုံးပြုသော command။</li> <li><strong><code>Seq2SeqTrainingArguments</code></strong>: 🤗 Transformers library မှ sequence-to-sequence models များကို train လုပ်ရန်အတွက် training arguments များကို သတ်မှတ်ပေးသော class။</li> <li><strong><code>Seq2SeqTrainer</code></strong>: 🤗 Transformers library မှ sequence-to-sequence models များကို လေ့ကျင့်ရန်အတွက် မြင့်မားသောအဆင့် (high-level) API။</li> <li><strong>Hyperparameters</strong>: Model ကို မလေ့ကျင့်မီ သတ်မှတ်ရသော parameters များ (ဥပမာ- learning rate, batch size)။</li> <li><strong><code>output_dir</code></strong>: Training outputs များကို သိမ်းဆည်းမည့် directory။</li> <li><strong><code>evaluation_strategy="epoch"</code></strong>: Training လုပ်နေစဉ် evaluation ကို epoch တိုင်းတွင် ပြုလုပ်ရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>learning_rate</code></strong>: Training လုပ်ငန်းစဉ်အတွင်း model ၏ weights များကို မည်မျှပြောင်းလဲရမည်ကို ထိန်းချုပ်သော parameter။</li> <li><strong><code>per_device_train_batch_size</code></strong>: device တစ်ခုစီ (ဥပမာ- GPU) ပေါ်တွင် training အတွက် batch size။</li> <li><strong><code>per_device_eval_batch_size</code></strong>: device တစ်ခုစီ (ဥပမာ- GPU) ပေါ်တွင် evaluation အတွက် batch size။</li> <li><strong><code>weight_decay</code></strong>: Overfitting ကို လျှော့ချရန်အတွက် optimizer တွင် အသုံးပြုသော regularization နည်းလမ်း။</li> <li><strong><code>save_total_limit</code></strong>: training လုပ်နေစဉ် သိမ်းဆည်းထားမည့် checkpoints အရေအတွက်ကို ကန့်သတ်ခြင်း။</li> <li><strong><code>num_train_epochs</code></strong>: Model ကို training dataset တစ်ခုလုံးဖြင့် လေ့ကျင့်သည့် အကြိမ်အရေအတွက်။</li> <li><strong><code>predict_with_generate=True</code></strong>: <code>Seq2SeqTrainer</code> ကို evaluation လုပ်နေစဉ် <code>model.generate()</code> method ကို အသုံးပြု၍ summaries များ ထုတ်လုပ်ရန် ညွှန်ကြားခြင်း။</li> <li><strong><code>logging_steps</code></strong>: training loss ကို မည်မျှ steps ကြာတိုင်း log လုပ်မည်ကို သတ်မှတ်ခြင်း။</li> <li><strong><code>push_to_hub=True</code></strong>: training ပြီးနောက် model ကို Hugging Face Hub သို့ push လုပ်ရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>hub_model_id</code> Argument</strong>: Hugging Face Hub သို့ push လုပ်မည့် repository ၏ ID ကို သတ်မှတ်ရန် argument။</li> <li><strong>Organization</strong>: Hugging Face Hub တွင် models များနှင့် datasets များကို စုစည်းပြီး မျှဝေရန် အသုံးပြုသော အဖွဲ့အစည်းအကောင့်။</li> <li><strong><code>compute_metrics()</code> Function</strong>: model ၏ predictions များနှင့် ground truth labels များကို အသုံးပြု၍ evaluation metrics များကို တွက်ချက်ရန် function။</li> <li><strong><code>eval_pred</code></strong>: <code>compute_metrics</code> function သို့ ပေးပို့သော predictions နှင့် labels အတွဲ။</li> <li><strong><code>predictions</code></strong>: Model မှ ထုတ်လုပ်သော ခန့်မှန်းချက်များ (tokens ID များ)။</li> <li><strong><code>labels</code></strong>: Ground truth labels (tokens ID များ)။</li> <li><strong><code>tokenizer.batch_decode()</code></strong>: batch တစ်ခုအတွင်းရှိ tokens ID များကို text အဖြစ် decode လုပ်သော tokenizer method။</li> <li><strong><code>skip_special_tokens=True</code></strong>: decoding လုပ်နေစဉ် special tokens များကို ကျော်သွားရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>np.where(labels != -100, labels, tokenizer.pad_token_id)</code></strong>: NumPy function တစ်ခုဖြစ်ပြီး labels array ထဲက <code>-100</code> တွေကို <code>tokenizer.pad_token_id</code> နဲ့ အစားထိုးသည်။</li> <li><strong><code>use_stemmer=True</code></strong>: ROUGE score တွက်ချက်ရာတွင် stemming ကို အသုံးပြုရန် သတ်မှတ်ခြင်း။</li> <li><strong>Median Scores</strong>: scores များ၏ အလယ်တန်ဖိုး။</li> <li><strong>Data Collator</strong>: batch တစ်ခုအတွင်း samples များကို စုစည်းပေးသော function။</li> <li><strong>Encoder-decoder Transformer Model</strong>: Transformer architecture တစ်မျိုးဖြစ်ပြီး input sequence ကို encode လုပ်ရန် encoder နှင့် output sequence ကို decode လုပ်ရန် decoder နှစ်ခုပါဝင်သည်။</li> <li><strong>Ground Truth Labels</strong>: မှန်ကန်သော သို့မဟုတ် အမှန်တကယ် labels များ။</li> <li><strong>Masked Self-attention</strong>: Transformer တွင် self-attention mechanism ကို အသုံးပြုပြီး အချို့သော input tokens များကို ဖုံးကွယ်ထားခြင်း။</li> <li><strong><code>DataCollatorForSeq2Seq</code></strong>: Hugging Face Transformers library မှ sequence-to-sequence models များအတွက် dynamic padding ကို လုပ်ဆောင်ပေးသော data collator။</li> <li><strong>Dynamically Pad</strong>: batch တစ်ခုအတွင်းရှိ samples များကို အဲဒီ batch ထဲက အရှည်ဆုံး sample ရဲ့ အရှည်အထိသာ padding လုပ်ခြင်း။</li> <li><strong><code>tokenized_datasets.remove_columns()</code></strong>: dataset မှ column များကို ဖယ်ရှားရန် method။</li> <li><strong><code>column_names</code></strong>: dataset ၏ column အမည်များစာရင်း။</li> <li><strong><code>dict</code></strong>: Python ၏ dictionary data structure။</li> <li><strong><code>input_ids</code></strong>: Tokenizer မှ ထုတ်ပေးသော tokens တစ်ခုစီ၏ ထူးခြားသော ဂဏန်းဆိုင်ရာ ID များ။</li> <li><strong><code>attention_mask</code></strong>: မော်ဒယ်ကို အာရုံစိုက်သင့်သည့် tokens များနှင့် လျစ်လျူရှုသင့်သည့် (padding) tokens များကို ခွဲခြားပေးသည့် binary mask။</li> <li><strong><code>[PAD]</code> Token</strong>: Padding အတွက် အသုံးပြုသော special token။</li> <li><strong><code>pad_token_id</code></strong>: Padding token ၏ ID။</li> <li><strong><code>decoder_input_ids</code></strong>: Decoder သို့ input အဖြစ် ပေးပို့သော ID များ။ labels များကို ညာဘက်သို့ ရွှေ့ထားသော ပုံစံဖြစ်သည်။</li> <li><strong><code>Seq2SeqTrainer</code></strong>: Hugging Face Transformers library မှ sequence-to-sequence models များကို လေ့ကျင့်ရန်အတွက် မြင့်မားသောအဆင့် (high-level) API။</li> <li><strong><code>trainer.train()</code></strong>: training လုပ်ငန်းစဉ်ကို စတင်ရန် method။</li> <li><strong><code>trainer.evaluate()</code></strong>: model ၏ စွမ်းဆောင်ရည်ကို အကဲဖြတ်ရန် method။</li> <li><strong><code>eval_loss</code></strong>: Evaluation dataset ပေါ်ရှိ loss တန်ဖိုး။</li> <li><strong><code>eval_rouge1</code>, <code>eval_rouge2</code>, <code>eval_rougeL</code>, <code>eval_rougeLsum</code></strong>: Evaluation dataset ပေါ်ရှိ ROUGE scores များ။</li> <li><strong><code>eval_gen_len</code></strong>: Generated summaries များ၏ ပျမ်းမျှအရှည်။</li> <li><strong><code>eval_runtime</code></strong>: Evaluation လုပ်ဆောင်ရန် ကြာမြင့်သော အချိန်။</li> <li><strong><code>eval_samples_per_second</code></strong>: တစ်စက္ကန့်လျှင် လုပ်ဆောင်သော samples အရေအတွက်။</li> <li><strong><code>eval_steps_per_second</code></strong>: တစ်စက္ကန့်လျှင် လုပ်ဆောင်သော training steps အရေအတွက်။</li> <li><strong>Lead-3 Baseline</strong>: Text summarization တွင် article တစ်ခု၏ ပထမဆုံး sentences သုံးခုကို summary အဖြစ် ယူသော baseline။</li> <li><strong><code>trainer.push_to_hub()</code></strong>: model weights များနှင့် configuration files များကို Hugging Face Hub သို့ push လုပ်ရန် method။</li> <li><strong><code>commit_message</code></strong>: Git commit အတွက် မက်ဆေ့ခ်ျ။</li> <li><strong><code>tags</code></strong>: Hub ပေါ်ရှိ model ကို categorize လုပ်ရန် အသုံးပြုသော tags များ။</li> <li><strong>Text Generation Pipeline</strong>: စာသားအသစ်များ ထုတ်လုပ်ရန်အတွက် ဒီဇိုင်းထုတ်ထားသော pipeline။</li> <li><strong>Git Commit Hash</strong>: Git repository တွင် commit တစ်ခုစီကို ကိုယ်စားပြုသော ထူးခြားသည့် ID။</li> <li><strong>Model Repository</strong>: Git version control system ကို အသုံးပြု၍ model file များ၊ tokenizer file များ၊ model card (README.md) နှင့် အခြားဆက်စပ်ဖိုင်များကို သိမ်းဆည်းထားသော နေရာ။</li> <li><strong>Low-level Features</strong>: library ၏ အသေးစိတ်လုပ်ဆောင်မှုများကို တိုက်ရိုက်ထိန်းချုပ်နိုင်သော functions သို့မဟုတ် methods များ။</li> <li><strong>🤗 Accelerate</strong>: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး PyTorch code တွေကို မတူညီတဲ့ training environment (ဥပမာ - GPU အများအပြား၊ distributed training) တွေမှာ အလွယ်တကူ run နိုင်အောင် ကူညီပေးပါတယ်။</li> <li><strong><code>tf.data.Dataset</code></strong>: TensorFlow framework တွင် data pipeline များကို ဖန်တီးရန် အသုံးပြုသော dataset object။</li> <li><strong><code>model.prepare_tf_dataset()</code></strong>: Hugging Face <code>Dataset</code> object ကို TensorFlow <code>tf.data.Dataset</code> သို့ ပြောင်းလဲရန် method။</li> <li><strong><code>collate_fn</code></strong>: <code>tf.data.Dataset</code> တွင် batch တစ်ခုအတွင်း samples များကို စုစည်းရန် အသုံးပြုသော function (Data Collator)။</li> <li><strong><code>shuffle=True</code></strong>: dataset ကို shuffle လုပ်ရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>batch_size</code></strong>: training လုပ်ငန်းစဉ်တစ်ခုစီတွင် model သို့ ပေးပို့သော input samples အရေအတွက်။</li> <li><strong><code>optimizer</code></strong>: Model ၏ parameters များကို update လုပ်ရန် အသုံးပြုသော algorithm။</li> <li><strong><code>schedule</code></strong>: Learning rate schedule။</li> <li><strong><code>create_optimizer()</code></strong>: Hugging Face Transformers library မှ optimizer နှင့် learning rate schedule ကို ဖန်တီးရန် function။</li> <li><strong><code>tensorflow as tf</code></strong>: TensorFlow library ကို <code>tf</code> အဖြစ် import လုပ်ခြင်း။</li> <li><strong><code>init_lr</code></strong>: ကနဦး learning rate။</li> <li><strong><code>num_warmup_steps</code></strong>: Training အစပိုင်းတွင် learning rate ကို တဖြည်းဖြည်း တိုးမြှင့်မည့် steps အရေအတွက်။</li> <li><strong><code>num_train_steps</code></strong>: စုစုပေါင်း training steps အရေအတွက်။</li> <li><strong><code>weight_decay_rate</code></strong>: <code>weight_decay</code> အတွက် rate။</li> <li><strong><code>model.compile()</code></strong>: Keras model ကို training အတွက် ပြင်ဆင်ရန် method။</li> <li><strong><code>tf.keras.mixed_precision.set_global_policy("mixed_float16")</code></strong>: TensorFlow တွင် mixed-precision training ကို ဖွင့်ရန် သတ်မှတ်ခြင်း။</li> <li><strong>Mixed-precision Float16</strong>: training လုပ်နေစဉ် floating-point numbers များကို 16-bit format ဖြင့် အသုံးပြုခြင်း။ ၎င်းသည် memory အသုံးပြုမှုကို လျှော့ချပြီး training ကို အရှိန်မြှင့်သည်။</li> <li><strong><code>model.fit()</code></strong>: Keras model ကို training လုပ်ရန် method။</li> <li><strong><code>validation_data</code></strong>: Training လုပ်နေစဉ် evaluation အတွက် အသုံးပြုမည့် dataset။</li> <li><strong><code>callbacks</code></strong>: Training လုပ်နေစဉ် သတ်မှတ်ထားသော အချိန်များတွင် လုပ်ဆောင်မည့် functions များ (ဥပမာ- <code>PushToHubCallback</code>)။</li> <li><strong><code>epochs</code></strong>: Model ကို training dataset တစ်ခုလုံးဖြင့် လေ့ကျင့်သည့် အကြိမ်အရေအတွက်။</li> <li><strong><code>PushToHubCallback</code></strong>: Hugging Face Transformers Keras callback တစ်ခုဖြစ်ပြီး training လုပ်နေစဉ် model ကို Hub သို့ push လုပ်ရန်။</li> <li><strong><code>tqdm</code></strong>: Python library တစ်ခုဖြစ်ပြီး loops တွေအတွက် progress bar တွေကို ပြသပေးသည်။</li> <li><strong>XLA (Accelerated Linear Algebra)</strong>: TensorFlow ရဲ့ compiler တစ်ခုဖြစ်ပြီး deep learning models တွေကို performance မြှင့်တင်ပေးသည်။</li> <li><strong>Computation Graph</strong>: TensorFlow model ၏ operations များနှင့် ၎င်းတို့ ချိတ်ဆက်ပုံကို ဖော်ပြသော graph။</li> <li><strong><code>@tf.function(jit_compile=True)</code> Decorator</strong>: Python function တစ်ခုကို TensorFlow Graph function အဖြစ် compile လုပ်ရန် သတ်မှတ်ခြင်း။ <code>jit_compile=True</code> က XLA compilation ကို ဖွင့်သည်။</li> <li><strong><code>generate_with_xla()</code> Function</strong>: XLA compilation ဖြင့် model ၏ <code>generate()</code> method ကို အသုံးပြုသော function။</li> <li><strong><code>max_new_tokens</code></strong>: Generated output ၏ အများဆုံး tokens အရေအတွက်။</li> <li><strong><code>tqdm</code></strong>: Python library တစ်ခုဖြစ်ပြီး loops တွေအတွက် progress bar တွေကို ပြသပေးသည်။</li> <li><strong><code>all_preds</code></strong>: Generated predictions များကို သိမ်းဆည်းထားသော list။</li> <li><strong><code>all_labels</code></strong>: Ground truth labels များကို သိမ်းဆည်းထားသော list။</li> <li><strong><code>DataLoader</code> (PyTorch)</strong>: Dataset ကနေ data တွေကို batch အလိုက် load လုပ်ပေးတဲ့ PyTorch utility class။</li> <li><strong><code>tokenized_datasets.set_format("torch")</code></strong>: dataset ၏ output format ကို PyTorch tensors အဖြစ် သတ်မှတ်ခြင်း။</li> <li><strong><code>torch.utils.data.DataLoader</code></strong>: PyTorch ၏ <code>DataLoader</code> class။</li> <li><strong><code>AdamW</code></strong>: PyTorch မှာ အသုံးပြုတဲ့ AdamW optimizer။ Model ၏ parameters များကို training လုပ်ရာမှာ အသုံးပြုသည်။</li> <li><strong><code>model.parameters()</code></strong>: model ၏ လေ့ကျင့်နိုင်သော parameters (weights နှင့် biases) များကို ပြန်ပေးသော method။</li> <li><strong><code>lr</code></strong>: Learning rate။</li> <li><strong><code>Accelerator</code></strong>: 🤗 Accelerate library ၏ class တစ်ခုဖြစ်ပြီး distributed training setting တွင် model, optimizer, dataloaders များကို ပြင်ဆင်ရန်။</li> <li><strong><code>accelerator.prepare()</code></strong>: model, optimizer, dataloaders များကို distributed training အတွက် ပြင်ဆင်ရန် Accelerate method။</li> <li><strong>TPU (Tensor Processing Unit)</strong>: Google မှ AI/ML workloads များအတွက် အထူးဒီဇိုင်းထုတ်ထားသော processor တစ်မျိုး။</li> <li><strong>Learning Rate Schedule</strong>: Training လုပ်နေစဉ် learning rate ကို မည်သို့ပြောင်းလဲမည်ကို သတ်မှတ်သော strategy။</li> <li><strong><code>get_scheduler()</code></strong>: Hugging Face Transformers library မှ learning rate scheduler ကို ဖန်တီးရန် function။</li> <li><strong><code>num_update_steps_per_epoch</code></strong>: epoch တစ်ခုစီတွင် update လုပ်သော steps အရေအတွက်။</li> <li><strong><code>num_training_steps</code></strong>: စုစုပေါင်း training steps အရေအတွက်။</li> <li><strong><code>postprocess_text()</code> Function</strong>: generated summaries များကို evaluation အတွက် ပြင်ဆင်ရန် function။</li> <li><strong><code>nltk.sent_tokenize()</code></strong>: <code>nltk</code> မှ စာသားတစ်ခုကို sentences များအဖြစ် ပိုင်းခြားပေးသော function။</li> <li><strong>🤗 Hub Library</strong>: Hugging Face Hub နှင့် အပြန်အလှန်ဆက်သွယ်ရန် Python library။</li> <li><strong><code>get_full_repo_name()</code> Function</strong>: Hugging Face Hub တွင် repository ID ကို user profile နှင့် ပေါင်းစပ်ပြီး repository ၏ အမည်အပြည့်အစုံကို ရယူရန် function။</li> <li><strong><code>repo_name</code></strong>: Repository ၏ အမည်အပြည့်အစုံ။</li> <li><strong><code>Repository</code> Class</strong>: <code>huggingface_hub</code> library မှ Git repository များကို ကိုင်တွယ်ရန်အတွက် class။</li> <li><strong><code>output_dir</code></strong>: Training outputs များကို သိမ်းဆည်းမည့် directory။</li> <li><strong><code>clone_from</code></strong>: remote repository မှ local repository သို့ clone လုပ်ရန် URL။</li> <li><strong><code>repo.push_to_hub()</code> Method</strong>: <code>Repository</code> object မှ changes များကို Hub သို့ push လုပ်ရန် method။</li> <li><strong><code>blocking=False</code></strong>: <code>push_to_hub()</code> method တွင် asynchronous (တစ်ပြိုင်နက်တည်းမဟုတ်ဘဲ) push ကို ခွင့်ပြုရန် argument။</li> <li><strong>Asynchronously</strong>: လုပ်ငန်းစဉ်တစ်ခု ပြီးဆုံးရန် မစောင့်ဘဲ နောက်ထပ်လုပ်ငန်းစဉ်များကို ဆက်လက်လုပ်ဆောင်ခြင်း။</li> <li><strong><code>progress_bar</code></strong>: <code>tqdm</code> library မှ progress bar object။</li> <li><strong><code>model.train()</code></strong>: PyTorch model ကို training mode သို့ ပြောင်းလဲခြင်း။</li> <li><strong><code>model.eval()</code></strong>: PyTorch model ကို evaluation mode သို့ ပြောင်းလဲခြင်း။</li> <li><strong>`outputs = model(</strong>batch)`**: model ကို input batch ဖြင့် run ပြီး outputs များကို ရယူခြင်း။</li> <li><strong><code>loss = outputs.loss</code></strong>: model output မှ loss value ကို ရယူခြင်း။</li> <li><strong><code>accelerator.backward(loss)</code></strong>: Accelerate ဖြင့် loss ကို backpropagate လုပ်ခြင်း။</li> <li><strong><code>optimizer.step()</code></strong>: optimizer မှ model parameters များကို update လုပ်ခြင်း။</li> <li><strong><code>lr_scheduler.step()</code></strong>: learning rate scheduler မှ learning rate ကို update လုပ်ခြင်း။</li> <li><strong><code>optimizer.zero_grad()</code></strong>: optimizer ၏ gradients များကို သုညသို့ ပြန်သတ်မှတ်ခြင်း။</li> <li><strong><code>progress_bar.update(1)</code></strong>: progress bar ကို တစ်ဆင့် တိုးမြှင့်ခြင်း။</li> <li><strong><code>torch.no_grad()</code></strong>: PyTorch တွင် gradient calculation ကို ပိတ်ခြင်း (evaluation အတွက်)။</li> <li><strong><code>accelerator.unwrap_model(model)</code></strong>: Accelerate ဖြင့် wrap လုပ်ထားသော model မှ underlying model ကို ရယူခြင်း။</li> <li><strong><code>model.generate()</code></strong>: model မှ output sequence ကို ထုတ်လုပ်ရန် method။</li> <li><strong><code>accelerator.pad_across_processes()</code></strong>: Distributed training တွင် processes များအလိုက် tensors များကို padding လုပ်ရန် Accelerate method။</li> <li><strong><code>dim</code></strong>: padding လုပ်မည့် dimension။</li> <li><strong><code>pad_index</code></strong>: padding အတွက် အသုံးပြုမည့် ID။</li> <li><strong><code>accelerator.gather()</code></strong>: Distributed training တွင် processes များအလိုက် tensors များကို စုစည်းရန် Accelerate method။</li> <li><strong><code>cpu().numpy()</code></strong>: PyTorch tensor ကို CPU သို့ ရွှေ့ပြီး NumPy array အဖြစ် ပြောင်းလဲခြင်း။</li> <li><strong><code>isinstance(generated_tokens, tuple)</code></strong>: <code>generated_tokens</code> သည် tuple အမျိုးအစားဖြစ်ခြင်းရှိမရှိ စစ်ဆေးခြင်း။</li> <li><strong><code>rouge_score.add_batch()</code></strong>: batch တစ်ခုအတွက် predictions နှင့် references များကို ROUGE metric သို့ ထည့်သွင်းခြင်း။</li> <li><strong><code>rouge_score.compute()</code></strong>: စုစည်းထားသော predictions နှင့် references များအတွက် ROUGE scores များကို တွက်ချက်ခြင်း။</li> <li><strong><code>accelerator.wait_for_everyone()</code></strong>: Distributed training တွင် processes အားလုံး ပြီးဆုံးရန် စောင့်ဆိုင်းခြင်း။</li> <li><strong><code>unwrapped_model.save_pretrained()</code></strong>: pretrained model ၏ weights များကို သိမ်းဆည်းရန် method။</li> <li><strong><code>save_function=accelerator.save</code></strong>: Accelerate ဖြင့် save လုပ်ရန် function ကို သတ်မှတ်ခြင်း။</li> <li><strong><code>accelerator.is_main_process</code></strong>: လက်ရှိ process သည် main process ဖြစ်ခြင်းရှိမရှိ စစ်ဆေးခြင်း။</li> <li><strong><code>tokenizer.save_pretrained(output_dir)</code></strong>: tokenizer ၏ files များကို သိမ်းဆည်းရန် method။</li> <li><strong>Inference Widget</strong>: Hugging Face Hub ပေါ်တွင် model ကို web interface မှတစ်ဆင့် စမ်းသပ်နိုင်သော ကိရိယာ။</li> <li><strong><code>pipeline()</code> Object</strong>: Hugging Face Transformers library မှ model ကို အသုံးပြုရလွယ်ကူစေသော object။</li> <li><strong><code>hub_model_id</code></strong>: Hugging Face Hub ပေါ်ရှိ model ၏ ID။</li> <li><strong><code>summarizer</code></strong>: summarization pipeline object။</li> <li><strong><code>summary_text</code></strong>: pipeline မှ ထုတ်ပေးသော summary text။</li> <li><strong><code>print_summary()</code> Function</strong>: review, title, နှင့် generated summary များကို print လုပ်ရန် function။</li> <li><strong>Abstractive Summarization</strong>: input text မှ စကားလုံးများကို တိုက်ရိုက်ကူးယူခြင်းမဟုတ်ဘဲ၊ model က ကိုယ်ပိုင်စကားလုံးများဖြင့် အဓိပ္ပာယ်ကို နားလည်ပြီး အနှစ်ချုပ်ကို ထုတ်လုပ်ခြင်း။</li> <li><strong>Extractive Summarization</strong>: input text မှ မူရင်းစာကြောင်းများ သို့မဟုတ် စကားလုံးများကို ရွေးထုတ်ပြီး အနှစ်ချုပ်ကို ဖန်တီးခြင်း။</li> <li><strong>Bilingual</strong>: ဘာသာစကားနှစ်မျိုး။</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/chapter7/5.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_5q47hu = { | |
| assets: "/docs/course/pr_1095/my", | |
| base: "/docs/course/pr_1095/my", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/course/pr_1095/my/_app/immutable/entry/start.8e25cab6.js"), | |
| import("/docs/course/pr_1095/my/_app/immutable/entry/app.b12ce275.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 81], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 306 kB
- Xet hash:
- 5c54b272580debd7dd40853d06fe4225285a55b353b612f38d7d0e0a082d9ba6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.