course documentation
Transformers တွေက ဘာတွေလုပ်နိုင်လဲ။
Transformers တွေက ဘာတွေလုပ်နိုင်လဲ။
ဒီအပိုင်းမှာတော့ Transformer မော်ဒယ်တွေ ဘာတွေလုပ်နိုင်လဲဆိုတာကို ကြည့်ရှုသွားမှာဖြစ်ပြီး Hugging Face ရဲ့ 🤗 Transformers library ထဲက ပထမဆုံး ကိရိယာဖြစ်တဲ့ pipeline() function ကို အသုံးပြုသွားမှာပါ။
👀 ညာဘက်အပေါ်ထောင့်မှာရှိတဲ့ Open in Colab ခလုတ်ကို မြင်ရလား။ ဒီကဏ္ဍက code ဥပမာတွေ အားလုံးပါဝင်တဲ့ Google Colab notebook ကို ဖွင့်ဖို့ အဲဒီခလုတ်ကို နှိပ်လိုက်ပါ။ ဒီခလုတ်က code ဥပမာတွေ ပါဝင်တဲ့ မည်သည့်ကဏ္ဍမှာမဆို ရှိနေမှာပါ။
ဥပမာတွေကို ကိုယ်တိုင် run ချင်တယ်ဆိုရင်တော့ setup ကို လေ့လာကြည့်ဖို့ ကျွန်တော်တို့ အကြံပြုပါတယ်။
Transformers တွေက နေရာတိုင်းမှာ ရှိနေပါတယ်!
Transformer မော်ဒယ်တွေကို Natural Language Processing (NLP), computer vision, audio processing အပါအဝင် မတူညီတဲ့ နယ်ပယ်အသီးသီးက လုပ်ငန်းတာဝန်မျိုးစုံကို ဖြေရှင်းဖို့ အသုံးပြုပါတယ်။ အောက်ဖော်ပြပါ ကုမ္ပဏီတွေနဲ့ အဖွဲ့အစည်းအချို့ကတော့ Hugging Face နဲ့ Transformer မော်ဒယ်တွေကို အသုံးပြုနေကြပြီး ၎င်းတို့ရဲ့ မော်ဒယ်တွေကို မျှဝေခြင်းဖြင့် လူ့အဖွဲ့အစည်းကိုလည်း ပံ့ပိုးကူညီပေးနေကြပါတယ်။
🤗 Transformers library ကတော့ အဲဒီမျှဝေထားတဲ့ မော်ဒယ်တွေကို ဖန်တီးပြီး အသုံးပြုနိုင်တဲ့ functionality တွေကို ပံ့ပိုးပေးပါတယ်။ Model Hub မှာတော့ လူတိုင်း download လုပ်ပြီး အသုံးပြုနိုင်တဲ့ ကြိုတင်လေ့ကျင့်ထားသော (pretrained) မော်ဒယ်ပေါင်း သန်းချီ ပါဝင်ပါတယ်။ သင်ရဲ့ ကိုယ်ပိုင်မော်ဒယ်တွေကိုလည်း Hub ကို upload တင်နိုင်ပါတယ်။
⚠️ Hugging Face Hub ဟာ Transformer မော်ဒယ်တွေအတွက်ပဲ ကန့်သတ်ထားတာ မဟုတ်ပါဘူး။ လူတိုင်းက သူတို့လိုချင်တဲ့ မည်သည့်မော်ဒယ် သို့မဟုတ် dataset ကိုမဆို မျှဝေနိုင်ပါတယ်။ ရရှိနိုင်တဲ့ အင်္ဂါရပ်အားလုံးကို ရယူဖို့ huggingface.co account တစ်ခု ဖန်တီးပါ!
Transformer မော်ဒယ်တွေ ဘယ်လိုအလုပ်လုပ်လဲဆိုတာကို အသေးစိတ် မလေ့လာခင်မှာ စိတ်ဝင်စားစရာကောင်းတဲ့ NLP ပြဿနာအချို့ကို ဖြေရှင်းဖို့ ဘယ်လိုအသုံးပြုနိုင်လဲဆိုတာကို ဥပမာအချို့နဲ့ ကြည့်ရအောင်။
Pipelines တွေနဲ့ အလုပ်လုပ်ခြင်း
🤗 Transformers library ရဲ့ အခြေခံအကျဆုံး object ကတော့ pipeline() function ဖြစ်ပါတယ်။ ၎င်းက မော်ဒယ်တစ်ခုကို ၎င်းရဲ့ လိုအပ်တဲ့ preprocessing နဲ့ postprocessing အဆင့်တွေနဲ့ ချိတ်ဆက်ပေးပြီး ကျွန်တော်တို့ စာသားတစ်ခုခုကို တိုက်ရိုက်ထည့်သွင်းပြီး နားလည်လွယ်တဲ့ အဖြေတစ်ခု ရယူနိုင်စေပါတယ်။
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")[{'label': 'POSITIVE', 'score': 0.9598047137260437}]ကျွန်တော်တို့ စာကြောင်းများစွာကိုတောင် ပေးပို့နိုင်ပါတယ်။
classifier(
["I've been waiting for a HuggingFace course my whole life.", "I hate this so much!"]
)[{'label': 'POSITIVE', 'score': 0.9598047137260437},
{'label': 'NEGATIVE', 'score': 0.9994558095932007}]ပုံမှန်အားဖြင့် ဒီ pipeline ဟာ အင်္ဂလိပ်ဘာသာစကားမှာ sentiment analysis အတွက် fine-tune လုပ်ထားတဲ့ သီးခြား pretrained model တစ်ခုကို ရွေးချယ်ပေးပါတယ်။ classifier object ကို ဖန်တီးတဲ့အခါ မော်ဒယ်ကို download လုပ်ပြီး cache လုပ်ထားပါတယ်။ ဒီ command ကို ထပ် run တဲ့အခါ cache လုပ်ထားတဲ့ မော်ဒယ်ကို ပြန်သုံးမှာဖြစ်ပြီး မော်ဒယ်ကို ထပ် download လုပ်ဖို့ မလိုအပ်တော့ပါဘူး။
pipeline ထဲကို စာသားအချို့ ပေးပို့တဲ့အခါ အဓိက အဆင့်သုံးဆင့် ပါဝင်ပါတယ်။
- စာသားကို မော်ဒယ် နားလည်နိုင်တဲ့ ပုံစံအဖြစ် preprocessing လုပ်ပါတယ်။
- preprocessing လုပ်ထားတဲ့ inputs တွေကို မော်ဒယ်ဆီ ပေးပို့ပါတယ်။
- မော်ဒယ်ရဲ့ ခန့်မှန်းချက်တွေကို post-processing လုပ်ပြီး နားလည်လွယ်အောင် ပြန်ထုတ်ပေးပါတယ်။
မတူညီသော နယ်ပယ်များအတွက် ရနိုင်သော pipelines များ
The pipeline() function ဟာ မတူညီတဲ့ နယ်ပယ်များစွာ (multimodal) ကို ထောက်ပံ့ပေးပြီး စာသား၊ ပုံရိပ်၊ အသံနဲ့ multimodal လုပ်ငန်းတာဝန်တွေအထိ လုပ်ဆောင်နိုင်ပါတယ်။ ဒီသင်တန်းမှာတော့ စာသားလုပ်ငန်းတာဝန်တွေကို အဓိကထားမှာဖြစ်ပေမယ့် Transformer architecture ရဲ့ အလားအလာကို နားလည်ထားဖို့က အသုံးဝင်တာကြောင့် အကျဉ်းချုပ် ဖော်ပြပေးပါမယ်။
အောက်ဖော်ပြပါတို့ကတော့ ရရှိနိုင်တဲ့ အရာတွေရဲ့ အကျဉ်းချုပ် ဖြစ်ပါတယ်။
pipelines တွေရဲ့ ပြည့်စုံပြီး နောက်ဆုံးပေါ် စာရင်းအတွက် 🤗 Transformers documentation ကို ကြည့်ရှုပါ။
စာသား Pipelines (Text pipelines)
text-generation: prompt တစ်ခုမှ စာသားကို ဖန်တီးခြင်း။text-classification: စာသားကို ကြိုတင်သတ်မှတ်ထားသော အမျိုးအစားများအဖြစ် ခွဲခြားခြင်း။summarization: အဓိက အချက်အလက်များကို ထိန်းသိမ်းထားရင်း စာသားတစ်ခုကို ပိုမိုတိုတောင်းသော ပုံစံအဖြစ် ပြုလုပ်ခြင်း။translation: စာသားတစ်ခုကို ဘာသာစကားတစ်ခုမှ အခြားဘာသာစကားတစ်ခုသို့ ဘာသာပြန်ခြင်း။zero-shot-classification: သီးခြား label များပေါ်တွင် ကြိုတင်လေ့ကျင့်မှုမရှိဘဲ စာသားကို အမျိုးအစားခွဲခြားခြင်း။(Classify text without prior training on specific labels)feature-extraction: စာသားများ၏ vector representations များကို ထုတ်ယူခြင်း။
ပုံရိပ် Pipelines (Image pipelines)
image-to-text: ပုံရိပ်များ၏ စာသားဖော်ပြချက်များကို ဖန်တီးခြင်း။image-classification: ပုံရိပ်တစ်ခုရှိ အရာဝတ္ထုများကို ခွဲခြားသတ်မှတ်ခြင်း။object-detection: ပုံရိပ်များရှိ အရာဝတ္ထုများကို နေရာရှာပြီး ခွဲခြားသတ်မှတ်ခြင်း။
အသံ Pipelines (Audio pipelines)
automatic-speech-recognition: စကားပြောကို စာသားအဖြစ် ပြောင်းလဲခြင်း။audio-classification: အသံများကို အမျိုးအစားများအဖြစ် ခွဲခြားခြင်း။text-to-speech: စာသားကို ပြောဆိုသောအသံအဖြစ် ပြောင်းလဲခြင်း။
Multimodal pipelines
image-text-to-text: စာသား prompt တစ်ခုအပေါ် အခြေခံပြီး ပုံရိပ်တစ်ခုကို တုံ့ပြန်ခြင်း။
ဒီ pipelines အချို့ကို ပိုမိုအသေးစိတ် လေ့လာကြည့်ရအောင်။
Zero-shot classification
ကျွန်တော်တို့ စိန်ခေါ်မှု ပိုများတဲ့ လုပ်ငန်းတာဝန်တစ်ခုနဲ့ စတင်ပါမယ်။ အဲဒါကတော့ label မတပ်ရသေးတဲ့ စာသားတွေကို အမျိုးအစားခွဲခြားဖို့ လိုအပ်တဲ့ အလုပ်ပါ။ ဒါဟာ လက်တွေ့ကမ္ဘာ project တွေမှာ အဖြစ်များတဲ့ အခြေအနေတစ်ခုပါ။ ဘာလို့လဲဆိုတော့ စာသားတွေကို label တပ်ဖို့က အချိန်ကုန်လေ့ရှိပြီး နယ်ပယ်ဆိုင်ရာ ကျွမ်းကျင်မှု (domain expertise) လိုအပ်လို့ပါ။ ဒီလိုကိစ္စမျိုးအတွက် zero-shot-classification pipeline က အလွန်အစွမ်းထက်ပါတယ်။ ၎င်းက classification အတွက် အသုံးပြုရမယ့် labels တွေကို သတ်မှတ်နိုင်စေတာကြောင့် pretrained model ရဲ့ labels တွေကို အားကိုးစရာ မလိုတော့ပါဘူး။ မော်ဒယ်က စာကြောင်းတစ်ကြောင်းကို positive သို့မဟုတ် negative လို့ ဘယ်လိုခွဲခြားနိုင်လဲဆိုတာ သင်မြင်ပြီးပါပြီ — ဒါပေမယ့် သင်လိုချင်တဲ့ အခြား labels အစုအဝေးနဲ့လည်း စာသားကို ခွဲခြားနိုင်ပါသေးတယ်။
from transformers import pipeline
classifier = pipeline("zero-shot-classification")
classifier(
"This is a course about the Transformers library",
candidate_labels=["education", "politics", "business"],
){'sequence': 'This is a course about the Transformers library',
'labels': ['education', 'business', 'politics'],
'scores': [0.8445963859558105, 0.111976258456707, 0.043427448719739914]}ဒီ pipeline ကို zero-shot လို့ခေါ်တာကတော့ သင်ရဲ့ဒေတာပေါ်မှာ မော်ဒယ်ကို fine-tune လုပ်ဖို့ မလိုအပ်ဘဲ အသုံးပြုနိုင်လို့ပါ။ ဒါဟာ သင်လိုချင်တဲ့ labels စာရင်းအတွက် ဖြစ်နိုင်ခြေရမှတ် (probability scores) တွေကို တိုက်ရိုက်ပြန်ပေးနိုင်ပါတယ်။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။ သင်ရဲ့ ကိုယ်ပိုင် sequences နဲ့ labels တွေနဲ့ စမ်းသပ်ပြီး မော်ဒယ် ဘယ်လို အလုပ်လုပ်လဲ ကြည့်ပါ။
စာသား ဖန်တီးခြင်း (Text generation)
အခုတော့ စာသားအချို့ ဖန်တီးဖို့ pipeline ကို ဘယ်လိုအသုံးပြုလဲဆိုတာ ကြည့်ရအောင်။ ဒီနေရာမှာ အဓိကစိတ်ကူးက သင် prompt တစ်ခု ပေးလိုက်ရင် မော်ဒယ်က ကျန်ရှိတဲ့ စာသားကို ဖန်တီးပေးခြင်းဖြင့် auto-complete လုပ်ပေးပါလိမ့်မယ်။ ဒါက ဖုန်းတွေမှာ တွေ့ရတဲ့ predictive text feature နဲ့ ဆင်တူပါတယ်။ စာသားဖန်တီးခြင်းမှာ randomness ပါဝင်တာကြောင့် အောက်မှာ ပြထားတဲ့ ရလဒ်တွေအတိုင်း အတိအကျမရရင်လည်း ပုံမှန်ပါပဲ။
from transformers import pipeline
generator = pipeline("text-generation")
generator("In this course, we will teach you how to")[{'generated_text': 'In this course, we will teach you how to understand and use '
'data flow and data interchange when handling user data. We '
'will be working with one or more of the most commonly used '
'data flows — data flows of various types, as seen by the '
'HTTP'}]num_return_sequences argument နဲ့ ဖန်တီးမယ့် sequence အရေအတွက်ကို ထိန်းချုပ်နိုင်ပြီး max_length argument နဲ့ ထွက်ပေါ်လာမယ့် စာသားရဲ့ စုစုပေါင်းအရှည်ကို ထိန်းချုပ်နိုင်ပါတယ်။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။
num_return_sequencesနဲ့max_lengtharguments တွေကို အသုံးပြုပြီး စကားလုံး ၁၅ လုံးစီ ပါဝင်တဲ့ စာကြောင်းနှစ်ကြောင်း ဖန်တီးပါ။
Hub မှ မည်သည့်မော်ဒယ်ကိုမဆို pipeline ထဲတွင် အသုံးပြုခြင်း
အထက်ပါ ဥပမာတွေမှာတော့ လုပ်ငန်းတာဝန်အတွက် ပုံမှန်မော်ဒယ်ကို အသုံးပြုခဲ့တာဖြစ်ပေမယ့်၊ သီးခြားလုပ်ငန်းတစ်ခု — ဥပမာ စာသားဖန်တီးခြင်းအတွက် Hub ကနေ သီးခြားမော်ဒယ်တစ်ခုကိုလည်း pipeline ထဲမှာ ရွေးချယ်အသုံးပြုနိုင်ပါတယ်။ Model Hub ကိုသွားပြီး ဘယ်ဘက်ခြမ်းမှာရှိတဲ့ သက်ဆိုင်ရာ tag ကို နှိပ်လိုက်ရင် အဲဒီလုပ်ငန်းအတွက် ထောက်ပံ့ပေးတဲ့ မော်ဒယ်တွေကိုသာ ပြသပေးပါလိမ့်မယ်။ ဒီစာမျက်နှာ လို စာမျက်နှာကို သင်ရောက်သွားပါလိမ့်မယ်။
HuggingFaceTB/SmolLM2-360M မော်ဒယ်ကို စမ်းကြည့်ရအောင်။ အောက်ပါအတိုင်း အရင်ကအတိုင်း pipeline ထဲမှာ ထည့်သွင်း load လုပ်နိုင်ပါတယ်။
from transformers import pipeline
generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM2-360M")
generator(
"In this course, we will teach you how to",
max_length=30,
num_return_sequences=2,
)[{'generated_text': 'In this course, we will teach you how to manipulate the world and '
'move your mental and physical capabilities to your advantage.'},
{'generated_text': 'In this course, we will teach you how to become an expert and '
'practice realtime, and with a hands on experience on both real '
'time and real'}]ဘာသာစကား tags တွေကို နှိပ်ပြီး သင်ရဲ့မော်ဒယ်ရှာဖွေမှုကို ပိုမိုတိကျအောင် လုပ်ဆောင်နိုင်ပြီး အခြားဘာသာစကားနဲ့ စာသားဖန်တီးပေးမယ့် မော်ဒယ်တစ်ခုကို ရွေးချယ်နိုင်ပါတယ်။ Model Hub မှာ ဘာသာစကားမျိုးစုံကို ထောက်ပံ့ပေးတဲ့ multilingual model တွေအတွက် checkpoints တွေလည်း ပါဝင်ပါတယ်။
မော်ဒယ်တစ်ခုကို နှိပ်ပြီး ရွေးချယ်လိုက်တာနဲ့ ၎င်းကို တိုက်ရိုက် online မှာ စမ်းသပ်နိုင်တဲ့ widget တစ်ခုကို တွေ့ရပါလိမ့်မယ်။ ဒီနည်းနဲ့ မော်ဒယ်ကို download မလုပ်ခင်မှာ ၎င်းရဲ့စွမ်းဆောင်ရည်တွေကို အမြန်စမ်းသပ်နိုင်ပါတယ်။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။ အခြားဘာသာစကားတစ်ခုအတွက် text generation မော်ဒယ်တစ်ခုကို ရှာဖွေဖို့ filters တွေကို အသုံးပြုပါ။ widget နဲ့ စမ်းသပ်ပြီး pipeline ထဲမှာ အသုံးပြုနိုင်ပါတယ်။
Inference Providers များ
မော်ဒယ်အားလုံးကို Hugging Face website မှာ ရရှိနိုင်တဲ့ Inference Providers ကို အသုံးပြုပြီး သင့် browser ကနေ တိုက်ရိုက် စမ်းသပ်နိုင်ပါတယ်။ ဒီစာမျက်နှာမှာ စိတ်ကြိုက်စာသားထည့်သွင်းပြီး မော်ဒယ်က input data ကို ဘယ်လိုလုပ်ဆောင်လဲဆိုတာကို ကြည့်ရှုခြင်းဖြင့် မော်ဒယ်နဲ့ တိုက်ရိုက်ကစားနိုင်ပါတယ်။
Widget ကို စွမ်းဆောင်ပေးတဲ့ Inference Providers ကိုလည်း ငွေပေးချေရတဲ့ ထုတ်ကုန်အဖြစ် ရရှိနိုင်ပါတယ်။ ဒါက သင်ရဲ့ workflow တွေအတွက် လိုအပ်ရင် အလွန်အသုံးဝင်ပါတယ်။ အသေးစိတ်အတွက်pricing page ကို ကြည့်ပါ။
Mask filling
သင်စမ်းသပ်ရမယ့် နောက်ထပ် pipeline ကတော့ fill-mask ဖြစ်ပါတယ်။ ဒီလုပ်ငန်းတာဝန်ရဲ့ စိတ်ကူးက ပေးထားတဲ့ စာသားတစ်ခုမှာရှိတဲ့ ကွက်လပ်တွေကို ဖြည့်ဆည်းပေးဖို့ပါပဲ။
from transformers import pipeline
unmasker = pipeline("fill-mask")
unmasker("This course will teach you all about <mask> models.", top_k=2)[{'sequence': 'This course will teach you all about mathematical models.',
'score': 0.19619831442832947,
'token': 30412,
'token_str': ' mathematical'},
{'sequence': 'This course will teach you all about computational models.',
'score': 0.04052725434303284,
'token': 38163,
'token_str': ' computational'}]top_k argument က သင်ပြသ၊လိုတဲ့ ဖြစ်နိုင်ခြေ အရေအတွက်ကို ထိန်းချုပ်ပါတယ်။ ဒီနေရာမှာ မော်ဒယ်က <mask> ဆိုတဲ့ အထူးစကားလုံးကို ဖြည့်ပေးတာကို သတိပြုပါ။ ဒါကို mask token လို့ မကြာခဏ ရည်ညွှန်းလေ့ရှိပါတယ်။ အခြား mask-filling မော်ဒယ်တွေမှာ မတူညီတဲ့ mask token တွေ ရှိနိုင်တာကြောင့် အခြားမော်ဒယ်တွေကို လေ့လာတဲ့အခါ မှန်ကန်တဲ့ mask word ကို အမြဲစစ်ဆေးတာ ကောင်းပါတယ်။ စစ်ဆေးဖို့ နည်းလမ်းတစ်ခုကတော့ widget မှာ အသုံးပြုထားတဲ့ mask word ကို ကြည့်တာပါပဲ။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။ Hub ပေါ်မှာ
bert-base-casedမော်ဒယ်ကို ရှာဖွေပြီး Inference API widget မှာ ၎င်းရဲ့ mask word ကို ခွဲခြားသတ်မှတ်ပါ။ ကျွန်တော်တို့ရဲ့pipelineဥပမာမှာပါတဲ့ စာကြောင်းအတွက် ဒီမော်ဒယ်က ဘာကို ခန့်မှန်းပေးမလဲ။
Named entity recognition
Named Entity Recognition (NER) ဆိုတာက input text ထဲက ဘယ်အပိုင်းတွေက လူ၊ နေရာ ဒါမှမဟုတ် အဖွဲ့အစည်းလို entities တွေနဲ့ ကိုက်ညီလဲဆိုတာကို မော်ဒယ်က ရှာဖွေရတဲ့ လုပ်ငန်းတာဝန်တစ်ခု ဖြစ်ပါတယ်။ ဥပမာတစ်ခုကို ကြည့်ရအောင်။
from transformers import pipeline
ner = pipeline("ner", grouped_entities=True)
ner("My name is Sylvain and I work at Hugging Face in Brooklyn.")[{'entity_group': 'PER', 'score': 0.99816, 'word': 'Sylvain', 'start': 11, 'end': 18},
{'entity_group': 'ORG', 'score': 0.97960, 'word': 'Hugging Face', 'start': 33, 'end': 45},
{'entity_group': 'LOC', 'score': 0.99321, 'word': 'Brooklyn', 'start': 49, 'end': 57}
]ဒီနေရာမှာ မော်ဒယ်က Sylvain ဟာ လူ (PER) ဖြစ်ကြောင်း၊ Hugging Face က အဖွဲ့အစည်း (ORG) ဖြစ်ကြောင်း၊ Brooklyn က နေရာ (LOC) ဖြစ်ကြောင်း မှန်ကန်စွာ ဖော်ထုတ်ခဲ့ပါတယ်။
ကျွန်တော်တို့ grouped_entities=True option ကို pipeline ဖန်တီးတဲ့ function မှာ ပေးလိုက်တာက စာကြောင်းရဲ့ အစိတ်အပိုင်းတွေကို တူညီတဲ့ entity နဲ့ ကိုက်ညီတဲ့ အစိတ်အပိုင်းတွေကို အတူတကွ ပြန်လည်စုစည်းဖို့ pipeline ကို ပြောတာပါ။ ဒီနေရာမှာ မော်ဒယ်က “Hugging” နဲ့ “Face” ကို စကားလုံးများစွာနဲ့ ဖွဲ့စည်းထားတဲ့ နာမည်ဖြစ်ပေမယ့် တစ်ခုတည်းသော အဖွဲ့အစည်းအဖြစ် မှန်ကန်စွာ စုစည်းခဲ့ပါတယ်။ တကယ်တော့ နောက်အခန်းမှာ ကျွန်တော်တို့ မြင်ရမှာဖြစ်သလို preprocessing က စကားလုံးအချို့ကို ပိုမိုသေးငယ်တဲ့ အစိတ်အပိုင်းတွေအဖြစ် ခွဲထုတ်တာတောင် လုပ်ပါတယ်။ ဥပမာ၊ Sylvain ကို S၊ ##yl၊ ##va၊ ##in ဆိုပြီး လေးပိုင်းခွဲပါတယ်။ post-processing အဆင့်မှာတော့ pipeline က အဲဒီအပိုင်းတွေကို အောင်မြင်စွာ ပြန်လည်စုစည်းပေးပါတယ်။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။ Model Hub မှာ အင်္ဂလိပ်ဘာသာစကားမှာ part-of-speech tagging (အတိုကောက်အားဖြင့် POS) လုပ်ဆောင်နိုင်တဲ့ မော်ဒယ်တစ်ခုကို ရှာဖွေပါ။ အထက်ပါ ဥပမာမှာပါတဲ့ စာကြောင်းအတွက် ဒီမော်ဒယ်က ဘာကို ခန့်မှန်းပေးမလဲ။
မေးခွန်းဖြေဆိုခြင်း (Question answering)
question-answering pipeline ကတော့ ပေးထားတဲ့ အကြောင်းအရာတစ်ခုကနေ အချက်အလက်တွေကို အသုံးပြုပြီး မေးခွန်းတွေကို ဖြေပေးပါတယ်။
from transformers import pipeline
question_answerer = pipeline("question-answering")
question_answerer(
question="Where do I work?",
context="My name is Sylvain and I work at Hugging Face in Brooklyn",
){'score': 0.6385916471481323, 'start': 33, 'end': 45, 'answer': 'Hugging Face'}ဒီ pipeline က ပေးထားတဲ့ context ကနေ အချက်အလက်တွေကို ထုတ်ယူပြီး အလုပ်လုပ်တာကို သတိပြုပါ။ ၎င်းက အဖြေကို ဖန်တီးပေးတာ မဟုတ်ပါဘူး။
အနှစ်ချုပ်ခြင်း(Summarization)
Summarization ဆိုတာက စာသားတစ်ခုကို ပိုမိုတိုတောင်းတဲ့ စာသားတစ်ခုအဖြစ် လျှော့ချပြီး စာသားမှာ ရည်ညွှန်းထားတဲ့ အရေးကြီးတဲ့ အချက်အလက်အားလုံး (သို့မဟုတ် အများစု) ကို ထိန်းသိမ်းထားတဲ့ လုပ်ငန်းတာဝန် ဖြစ်ပါတယ်။ ဥပမာတစ်ခုကို ကြည့်ရအောင်။
from transformers import pipeline
summarizer = pipeline("summarization")
summarizer(
"""
America has changed dramatically during recent years. Not only has the number of
graduates in traditional engineering disciplines such as mechanical, civil,
electrical, chemical, and aeronautical engineering declined, but in most of
the premier American universities engineering curricula now concentrate on
and encourage largely the study of engineering science. As a result, there
are declining offerings in engineering subjects dealing with infrastructure,
the environment, and related issues, and greater concentration on high
technology subjects, largely supporting increasingly complex scientific
developments. While the latter is important, it should not be at the expense
of more traditional engineering.
Rapidly developing economies such as China and India, as well as other
industrial countries in Europe and Asia, continue to encourage and advance
the teaching of engineering. Both China and India, respectively, graduate
six and eight times as many traditional engineers as does the United States.
Other industrial countries at minimum maintain their output, while America
suffers an increasingly serious decline in the number of engineering graduates
and a lack of well-educated engineers.
"""
)[{'summary_text': ' America has changed dramatically during recent years . The '
'number of engineering graduates in the U.S. has declined in '
'traditional engineering disciplines such as mechanical, civil '
', electrical, chemical, and aeronautical engineering . Rapidly '
'developing economies such as China and India, as well as other '
'industrial countries in Europe and Asia, continue to encourage '
'and advance engineering .'}]Text generation နဲ့ အလားတူပဲ၊ ရလဒ်အတွက် max_length သို့မဟုတ် min_length ကို သတ်မှတ်နိုင်ပါတယ်။
ဘာသာပြန်ခြင်း (Translation)
ဘာသာပြန်ခြင်းအတွက်တော့ လုပ်ငန်းတာဝန်အမည်မှာ ဘာသာစကားတွဲ (ဥပမာ- "translation_en_to_fr") ကို ပေးလိုက်ရင် default မော်ဒယ်ကို အသုံးပြုနိုင်ပါတယ်။ ဒါပေမယ့် အလွယ်ကူဆုံးနည်းလမ်းကတော့ Model Hub ကနေ သင်အသုံးပြုလိုတဲ့ မော်ဒယ်ကို ရွေးချယ်တာပါပဲ။ ဒီနေရာမှာတော့ ပြင်သစ်ဘာသာကနေ အင်္ဂလိပ်ဘာသာကို ဘာသာပြန်ကြည့်ပါမယ်။
from transformers import pipeline
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en")
translator("Ce cours est produit par Hugging Face.")[{'translation_text': 'This course is produced by Hugging Face.'}]Text generation နဲ့ summarization တွေလိုပဲ ရလဒ်အတွက် max_length သို့မဟုတ် min_length ကို သတ်မှတ်နိုင်ပါတယ်။
✏️ ကိုယ်တိုင် စမ်းကြည့်ပါဦး။ အခြားဘာသာစကားတွေမှာ ဘာသာပြန်မော်ဒယ်တွေကို ရှာဖွေပြီး အရင်စာကြောင်းကို မတူညီတဲ့ ဘာသာစကားအချို့ဆီ ဘာသာပြန်ကြည့်ပါ။
ပုံရိပ်နှင့် အသံ Pipelines များ (Image and audio pipelines)
စာသားအပြင် Transformer မော်ဒယ်တွေဟာ ပုံရိပ်နဲ့ အသံတွေနဲ့လည်း အလုပ်လုပ်နိုင်ပါတယ်။ ဥပမာအချို့ကတော့-
Image classification
from transformers import pipeline
image_classifier = pipeline(
task="image-classification", model="google/vit-base-patch16-224"
)
result = image_classifier(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
)
print(result)[{'label': 'lynx, catamount', 'score': 0.43350091576576233},
{'label': 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor',
'score': 0.034796204417943954},
{'label': 'snow leopard, ounce, Panthera uncia',
'score': 0.03240183740854263},
{'label': 'Egyptian cat', 'score': 0.02394474856555462},
{'label': 'tiger cat', 'score': 0.02288915030658245}]Automatic speech recognition
from transformers import pipeline
transcriber = pipeline(
task="automatic-speech-recognition", model="openai/whisper-large-v3"
)
result = transcriber(
"https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac"
)
print(result){'text': ' I have a dream that one day this nation will rise up and live out the true meaning of its creed.'}ဒေတာ အရင်းအမြစ်မျိုးစုံမှ ဒေတာများကို ပေါင်းစပ်ခြင်း (Combining data from multiple sources)
Transformer မော်ဒယ်တွေရဲ့ အစွမ်းထက်တဲ့ အသုံးချမှုတစ်ခုကတော့ ဒေတာအရင်းအမြစ်မျိုးစုံကနေ ဒေတာတွေကို ပေါင်းစပ်ပြီး လုပ်ဆောင်နိုင်စွမ်းပါပဲ။ ဒါက အောက်ပါကိစ္စတွေအတွက် အထူးအသုံးဝင်ပါတယ်။
- ဒေတာဘေ့စ်(databases)များစွာ သို့မဟုတ် repository များစွာကို ရှာဖွေခြင်း။
- တူညီတဲ့ format တွေ (စာသား၊ ပုံရိပ်၊ အသံ) ကနေ အချက်အလက်တွေကို စုစည်းခြင်း။
- ဆက်စပ်အချက်အလက်တွေရဲ့ ပေါင်းစပ်ထားသော မြင်ကွင်းတစ်ခုကို ဖန်တီးခြင်း။
ဥပမာအားဖြင့်၊ သင်ဟာ အောက်ပါတို့ကို လုပ်ဆောင်နိုင်တဲ့ စနစ်တစ်ခုကို တည်ဆောက်နိုင်ပါတယ်။
- စာသားနဲ့ ပုံရိပ်လို နယ်ပယ်အမျိုးစုံက ဒေတာဘေ့စ်တွေမှာ အချက်အလက်တွေကို ရှာဖွေခြင်း။
- မတူညီတဲ့ အရင်းအမြစ်တွေကနေ ရရှိတဲ့ ရလဒ်တွေကို တစ်ခုတည်းသော တုံ့ပြန်မှုအဖြစ် ပေါင်းစပ်ခြင်း။ ဥပမာ- အသံဖိုင်တစ်ခုနဲ့ စာသားဖော်ပြချက်တစ်ခုကနေ။
- document တွေနဲ့ metadata တွေရဲ့ ဒေတာဘေ့စ်တစ်ခုကနေ အသက်ဆိုင်ဆုံး အချက်အလက်တွေကို တင်ပြခြင်း။
နိဂုံးချုပ်
ဒီအခန်းမှာ ပြသထားတဲ့ pipelines တွေကတော့ အများစုက သရုပ်ပြရန်အတွက်သာ ဖြစ်ပါတယ်။ ၎င်းတို့ကို သီးခြားလုပ်ငန်းတာဝန်များအတွက် ရေးဆွဲထားတာဖြစ်ပြီး ၎င်းတို့ရဲ့ မူကွဲတွေကိုတော့ လုပ်ဆောင်နိုင်ခြင်း မရှိပါဘူး။ နောက်အခန်းမှာတော့ pipeline() function ထဲမှာ ဘာတွေပါလဲ၊ ၎င်းရဲ့ လုပ်ဆောင်ပုံကို ဘယ်လိုစိတ်ကြိုက် ပြုပြင်နိုင်လဲဆိုတာကို သင်လေ့လာရမှာ ဖြစ်ပါတယ်။
ဝေါဟာရ ရှင်းလင်းချက် (Glossary)
- Transformer Models: Natural Language Processing (NLP) မှာ အောင်မြင်မှုများစွာရရှိခဲ့တဲ့ deep learning architecture တစ်မျိုးပါ။ ၎င်းတို့ဟာ စာသားတွေထဲက စကားလုံးတွေရဲ့ ဆက်နွယ်မှုတွေကို “attention mechanism” သုံးပြီး နားလည်အောင် သင်ကြားပေးပါတယ်။
- 🤗 Transformers library: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး Transformer မော်ဒယ်တွေကို အသုံးပြုပြီး Natural Language Processing (NLP), computer vision, audio processing စတဲ့ နယ်ပယ်တွေမှာ အဆင့်မြင့် AI မော်ဒယ်တွေကို တည်ဆောက်ပြီး အသုံးပြုနိုင်စေပါတယ်။
pipeline()function: Hugging Face Transformers library မှာ ပါဝင်တဲ့ လုပ်ဆောင်ချက်တစ်ခုဖြစ်ပြီး မော်ဒယ်တွေကို သီးခြားလုပ်ငန်းတာဝန်များ (ဥပမာ- စာသားခွဲခြားသတ်မှတ်ခြင်း၊ စာသားထုတ်လုပ်ခြင်း) အတွက် အသုံးပြုရလွယ်ကူအောင် ပြုလုပ်ပေးပါတယ်။- Natural Language Processing (NLP): ကွန်ပျူတာတွေ လူသားဘာသာစကားကို နားလည်၊ အဓိပ္ပာယ်ဖော်ပြီး၊ ဖန်တီးနိုင်အောင် လုပ်ဆောင်ပေးတဲ့ Artificial Intelligence (AI) ရဲ့ နယ်ပယ်ခွဲတစ်ခု ဖြစ်ပါတယ်။ ဥပမာအားဖြင့် စာသားခွဲခြမ်းစိတ်ဖြာခြင်း၊ ဘာသာပြန်ခြင်း စသည်တို့ ပါဝင်ပါတယ်။
- Computer Vision: ကွန်ပျူတာများကို ပုံရိပ်များ၊ ဗီဒီယိုများကို လူသားများကဲ့သို့ မြင်၊ နားလည်နိုင်အောင် သင်ကြားပေးသည့် Artificial Intelligence (AI) နယ်ပယ်။
- Audio Processing: အသံအချက်အလက်များကို ခွဲခြမ်းစိတ်ဖြာခြင်း၊ ပြောင်းလဲခြင်း သို့မဟုတ် ဖန်တီးခြင်း လုပ်ငန်းများ။
- Model Hub: Hugging Face က ထုတ်လုပ်ထားတဲ့ အွန်လိုင်း platform တစ်ခုဖြစ်ပြီး AI မော်ဒယ်တွေ၊ datasets တွေနဲ့ demo တွေကို အခြားသူတွေနဲ့ မျှဝေဖို့၊ ရှာဖွေဖို့နဲ့ ပြန်လည်အသုံးပြုဖို့အတွက် ဖြစ်ပါတယ်။
- Pretrained Model: ကြီးမားသော ဒေတာအစုအဝေးများဖြင့် ကြိုတင်လေ့ကျင့်ထားသော Machine Learning မော်ဒယ်။ ၎င်းတို့ကို အခြားလုပ်ငန်းများအတွက် fine-tune ပြန်လုပ်နိုင်ပါတယ်။
- Fine-tuned: ကြိုတင်လေ့ကျင့်ထားပြီးသား (pre-trained) မော်ဒယ်တစ်ခုကို သီးခြားလုပ်ငန်းတစ်ခု (specific task) အတွက် အနည်းငယ်သော ဒေတာနဲ့ ထပ်မံလေ့ကျင့်ပေးခြင်းကို ဆိုလိုပါတယ်။
- Sentiment Analysis: စာသားတစ်ခုရဲ့ စိတ်ခံစားမှု (အပြုသဘော၊ အနုတ်သဘော၊ ကြားနေ) ကို ခွဲခြမ်းစိတ်ဖြာခြင်း။
- Preprocessing: ဒေတာများကို Machine Learning မော်ဒယ်တစ်ခုက နားလည်နိုင်သော ပုံစံသို့ ပြောင်းလဲရန် ပြင်ဆင်ခြင်းလုပ်ငန်းစဉ်။
- Postprocessing: Machine Learning မော်ဒယ်၏ ရလဒ်များကို လူသားများ နားလည်လွယ်သော ပုံစံသို့ ပြန်လည်ပြောင်းလဲခြင်းလုပ်ငန်းစဉ်။
- Multimodal: မတူညီသော ဒေတာအမျိုးအစားများ (ဥပမာ- စာသား၊ ပုံရိပ်၊ အသံ) ကို အသုံးပြုနိုင်စွမ်းရှိခြင်း။
- Text Generation: AI မော်ဒယ်များကို အသုံးပြု၍ လူသားကဲ့သို့သော စာသားအသစ်များ ဖန်တီးခြင်း။
- Text Classification: စာသားတစ်ခုကို ကြိုတင်သတ်မှတ်ထားသော အမျိုးအစားများအဖြစ် ခွဲခြားခြင်း။
- Summarization: အဓိက အချက်အလက်များကို ထိန်းသိမ်းထားရင်း စာသားတစ်ခုကို ပိုမိုတိုတောင်းသော ပုံစံအဖြစ် ပြုလုပ်ခြင်း။
- Translation: စာသားတစ်ခုကို ဘာသာစကားတစ်ခုမှ အခြားဘာသာစကားတစ်ခုသို့ ဘာသာပြန်ခြင်း။
- Zero-shot Classification: သီးခြား label များပေါ်တွင် ကြိုတင်လေ့ကျင့်မှုမရှိဘဲ စာသားကို အမျိုးအစားခွဲခြားခြင်း။
- Feature Extraction: ဒေတာများမှ အရေးကြီးသော လက္ခဏာရပ်များကို ထုတ်ယူခြင်း။
- Image to Text: ပုံရိပ်တစ်ခုမှ စာသားဖော်ပြချက်များကို ဖန်တီးခြင်း။
- Image Classification: ပုံရိပ်တစ်ခုရှိ အရာဝတ္ထုများကို ခွဲခြားသတ်မှတ်ခြင်း။
- Object Detection: ပုံရိပ်များရှိ အရာဝတ္ထုများကို နေရာရှာပြီး ခွဲခြားသတ်မှတ်ခြင်း။
- Automatic Speech Recognition: ပြောဆိုသော ဘာသာစကားကို ကွန်ပျူတာက စာသားအဖြစ် ပြောင်းလဲနားလည်နိုင်သည့် နည်းပညာ။
- Audio Classification: အသံများကို အမျိုးအစားများအဖြစ် ခွဲခြားခြင်း။
- Text to Speech: စာသားကို ပြောဆိုသောအသံအဖြစ် ပြောင်းလဲခြင်း။
- Image-Text to Text: ပုံရိပ်တစ်ခုနဲ့ ပတ်သက်ပြီး စာသား prompt တစ်ခုအပေါ် အခြေခံပြီး စာသားတုံ့ပြန်မှု ဖန်တီးခြင်း။
- Label: ဒေတာအချက်အလက်တစ်ခုကို ဖော်ပြရန် အသုံးပြုသော အမည် သို့မဟုတ် အမျိုးအစား။
- Domain Expertise: သီးခြားနယ်ပယ်တစ်ခု သို့မဟုတ် ဘာသာရပ်တစ်ခုတွင် နက်ရှိုင်းသော အသိပညာ သို့မဟုတ် ကျွမ်းကျင်မှု။
- Prompt: Large Language Models (LLMs) ကို တိကျသောလုပ်ငန်းတစ်ခု လုပ်ဆောင်ရန် သို့မဟုတ် အချက်အလက်ပေးရန်အတွက် ပေးပို့သော input text သို့မဟုတ် မေးခွန်း။
- Randomness: ကြိုတင်ခန့်မှန်းနိုင်ခြင်းမရှိသော သို့မဟုတ် အစီအစဉ်မရှိသော အခြေအနေများ။
num_return_sequences: text generation pipeline တွင် ဖန်တီးမည့် output sequence အရေအတွက်ကို ထိန်းချုပ်ရန် အသုံးပြုသော argument။max_length: text generation pipeline တွင် ထွက်ပေါ်လာမည့် output text ၏ အရှည်ဆုံး ဖြစ်နိုင်သော အရှည်ကို သတ်မှတ်ရန် အသုံးပြုသော argument။- Inference Providers: Hugging Face Hub ပေါ်ရှိ မော်ဒယ်များကို cloud-based API မှတစ်ဆင့် အသုံးပြုနိုင်စေသော ဝန်ဆောင်မှု။
- Mask Token:
fill-maskလုပ်ငန်းတာဝန်များတွင် စာသားထဲက ကွက်လပ်တစ်ခုကို ကိုယ်စားပြုသော အထူး token။ - Named Entity Recognition (NER): စာသားတစ်ခုထဲက လူအမည်၊ နေရာအမည်၊ အဖွဲ့အစည်းအမည် စတဲ့ သီးခြားအမည်တွေကို ရှာဖွေဖော်ထုတ်ခြင်း။
- Entities: အချက်အလက်များ သို့မဟုတ် အရာဝတ္ထုများ (ဥပမာ- လူ၊ နေရာ၊ အဖွဲ့အစည်း)။
grouped_entities: NER pipeline တွင် အတူတူရှိသော entity အပိုင်းအစများကို တစ်ခုတည်းအဖြစ် စုစည်းရန် အသုံးပြုသော option။- Part-of-speech Tagging (POS): စာကြောင်းတစ်ခုရှိ စကားလုံးတစ်လုံးစီ၏ သဒ္ဒါဆိုင်ရာ အစိတ်အပိုင်း (ဥပမာ- နာမ်၊ ကြိယာ၊ နာမဝိသေသန) ကို ခွဲခြားသတ်မှတ်ခြင်း။
- Question Answering: မေးခွန်းတစ်ခုနဲ့ ပေးထားတဲ့ အကြောင်းအရာတစ်ခုကနေ အချက်အလက်တွေကို ထုတ်ယူပြီး အဖြေရှာတဲ့ လုပ်ငန်းတာဝန်။
min_length: text generation သို့မဟုတ် summarization pipeline တွင် ထွက်ပေါ်လာမည့် output text ၏ အတိုဆုံး ဖြစ်နိုင်သော အရှည်ကို သတ်မှတ်ရန် အသုံးပြုသော argument။- Multilingual Models: ဘာသာစကားများစွာကို နားလည်ပြီး လုပ်ဆောင်နိုင်သော မော်ဒယ်များ။