Buckets:
Pretrained Models များကို အသုံးပြုခြင်း[[using-pretrained-models]]
{#if fw === 'pt'}
<CourseFloatingBanner chapter={4} classNames="absolute z-10 right-0 top-0" notebooks={[ {label: "Google Colab", value: "https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_pt.ipynb"}, {label: "Aws Studio", value: "https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_pt.ipynb"}, ]} />
{:else}
<CourseFloatingBanner chapter={4} classNames="absolute z-10 right-0 top-0" notebooks={[ {label: "Google Colab", value: "https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_tf.ipynb"}, {label: "Aws Studio", value: "https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter4/section2_tf.ipynb"}, ]} />
{/if}
Model Hub က သင့်လျော်တဲ့ model ကို ရွေးချယ်တာကို ရိုးရှင်းစေတာကြောင့်၊ downstream library တွေမှာ အသုံးပြုတာကို code လိုင်းအနည်းငယ်နဲ့ လုပ်ဆောင်နိုင်ပါတယ်။ ဒီ models တွေထဲက တစ်ခုကို လက်တွေ့ဘယ်လိုအသုံးပြုရမလဲ၊ ပြီးတော့ community ကို ဘယ်လိုပြန်လည်ပံ့ပိုးပေးရမလဲဆိုတာ ကြည့်ရအောင်။
ဥပမာအားဖြင့်၊ ကျွန်တော်တို့ဟာ mask filling ကို လုပ်ဆောင်နိုင်တဲ့ French-based model တစ်ခုကို ရှာနေတယ်လို့ ဆိုကြပါစို့။
ကျွန်တော်တို့ camembert-base checkpoint ကို စမ်းသပ်ဖို့ ရွေးချယ်လိုက်ပါတယ်။ camembert-base ဆိုတဲ့ identifier တစ်ခုတည်းကပဲ အဲဒါကို စတင်အသုံးပြုဖို့ လိုအပ်တဲ့ အရာအားလုံးပါပဲ! ယခင်အခန်းတွေမှာ သင်တွေ့ခဲ့ရတဲ့အတိုင်း၊ pipeline() function ကို အသုံးပြုပြီး instantiate လုပ်ဆောင်နိုင်ပါတယ်။
from transformers import pipeline
camembert_fill_mask = pipeline("fill-mask", model="camembert-base")
results = camembert_fill_mask("Le camembert est <mask> :)")
[
{'sequence': 'Le camembert est délicieux :)', 'score': 0.49091005325317383, 'token': 7200, 'token_str': 'délicieux'},
{'sequence': 'Le camembert est excellent :)', 'score': 0.1055697426199913, 'token': 2183, 'token_str': 'excellent'},
{'sequence': 'Le camembert est succulent :)', 'score': 0.03453313186764717, 'token': 26202, 'token_str': 'succulent'},
{'sequence': 'Le camembert est meilleur :)', 'score': 0.0330314114689827, 'token': 528, 'token_str': 'meilleur'},
{'sequence': 'Le camembert est parfait :)', 'score': 0.03007650189101696, 'token': 1654, 'token_str': 'parfait'}
]
သင်တွေ့ရတဲ့အတိုင်း၊ pipeline ထဲမှာ model တစ်ခုကို loading လုပ်တာက အလွန်ရိုးရှင်းပါတယ်။ သင်ဂရုစိုက်ရမယ့် တစ်ခုတည်းသောအရာကတော့ ရွေးချယ်ထားတဲ့ checkpoint က အသုံးပြုမယ့် task အတွက် သင့်လျော်ခြင်းရှိမရှိပါပဲ။ ဥပမာ၊ ဒီနေရာမှာ ကျွန်တော်တို့ camembert-base checkpoint ကို fill-mask pipeline မှာ loading လုပ်နေတာဖြစ်ပြီး၊ ဒါက လုံးဝအဆင်ပြေပါတယ်။ ဒါပေမယ့် ဒီ checkpoint ကို text-classification pipeline မှာ loading လုပ်မယ်ဆိုရင်တော့၊ camembert-base ရဲ့ head က ဒီ task အတွက် မသင့်လျော်တဲ့အတွက် ရလဒ်တွေဟာ ဘာမှ အဓိပ္ပာယ်ရှိမှာ မဟုတ်ပါဘူး! သင့်လျော်တဲ့ checkpoints တွေကို ရွေးချယ်နိုင်ဖို့ Hugging Face Hub interface မှာရှိတဲ့ task selector ကို အသုံးပြုဖို့ ကျွန်တော်တို့ အကြံပြုပါတယ်။
model architecture ကို တိုက်ရိုက်အသုံးပြုပြီး checkpoint ကိုလည်း instantiate လုပ်နိုင်ပါတယ်။
{#if fw === 'pt'}
from transformers import CamembertTokenizer, CamembertForMaskedLM
tokenizer = CamembertTokenizer.from_pretrained("camembert-base")
model = CamembertForMaskedLM.from_pretrained("camembert-base")
သို့သော်လည်း၊ Auto* classes တွေကို အသုံးပြုဖို့ ကျွန်တော်တို့ အကြံပြုပါတယ်၊ ဘာလို့လဲဆိုတော့ ဒါတွေဟာ architecture-agnostic ဖြစ်အောင် ဒီဇိုင်းထုတ်ထားလို့ပါပဲ။ ယခင် code sample က CamemBERT architecture မှာ load လုပ်နိုင်တဲ့ checkpoints တွေကိုသာ ကန့်သတ်ထားပေမယ့်၊ Auto* classes တွေကို အသုံးပြုခြင်းက checkpoints တွေ ပြောင်းတာကို ရိုးရှင်းစေပါတယ်။
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("camembert-base")
model = AutoModelForMaskedLM.from_pretrained("camembert-base")
{:else}
from transformers import CamembertTokenizer, TFCamembertForMaskedLM
tokenizer = CamembertTokenizer.from_pretrained("camembert-base")
model = TFCamembertForMaskedLM.from_pretrained("camembert-base")
သို့သော်လည်း၊ TFAuto* classes တွေကို အသုံးပြုဖို့ ကျွန်တော်တို့ အကြံပြုပါတယ်၊ ဘာလို့လဲဆိုတော့ ဒါတွေဟာ architecture-agnostic ဖြစ်အောင် ဒီဇိုင်းထုတ်ထားလို့ပါပဲ။ ယခင် code sample က CamemBERT architecture မှာ load လုပ်နိုင်တဲ့ checkpoints တွေကိုသာ ကန့်သတ်ထားပေမယ့်၊ TFAuto* classes တွေကို အသုံးပြုခြင်းက checkpoints တွေ ပြောင်းတာကို ရိုးရှင်းစေပါတယ်။
from transformers import AutoTokenizer, TFAutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("camembert-base")
model = TFAutoModelForMaskedLM.from_pretrained("camembert-base")
{/if}
pretrained model တစ်ခုကို အသုံးပြုတဲ့အခါ၊ ဒါကို ဘယ်လို train လုပ်ခဲ့လဲ၊ ဘယ် datasets တွေပေါ်မှာလဲ၊ ၎င်းရဲ့ ကန့်သတ်ချက်တွေနဲ့ ဘက်လိုက်မှုတွေကို သေချာစစ်ဆေးပါ။ ဒီအချက်အလက်အားလုံးကို ၎င်းရဲ့ model card မှာ ဖော်ပြထားသင့်ပါတယ်။ဝေါဟာရ ရှင်းလင်းချက် (Glossary)
- Model Hub: Hugging Face Hub ကို ရည်ညွှန်းပြီး AI မော်ဒယ်များ ရှာဖွေ၊ မျှဝေ၊ အသုံးပြုနိုင်သော ဗဟို platform။
- Downstream Library: အခြား library များ၏ အပေါ်တွင် တည်ဆောက်ထားသော သို့မဟုတ် ၎င်းတို့ကို အသုံးပြုသော library။
- Community: Hugging Face တွင် AI/ML နယ်ပယ်မှ သုံးစွဲသူများ၊ developer များနှင့် သုတေသီများ စုစည်းထားသော အဖွဲ့အစည်း။
- French-based Model: ပြင်သစ်ဘာသာစကားဖြင့် လေ့ကျင့်ထားသော AI မော်ဒယ်။
- Mask Filling: စာကြောင်းတစ်ခုထဲမှ ဖုံးကွယ်ထားသော (masked) စကားလုံးများကို model က ခန့်မှန်းဖြည့်ဆည်းပေးသည့် Natural Language Processing (NLP) လုပ်ငန်းတစ်ခု။
camembert-base: CamemBERT model ၏ base version အတွက် checkpoint identifier။- Checkpoint: မော်ဒယ်၏ weights များနှင့် အခြားဖွဲ့စည်းပုံများ (configuration) ကို သတ်မှတ်ထားသော အချိန်တစ်ခုတွင် သိမ်းဆည်းထားခြင်း။
- Identifier: သီးခြားအရာတစ်ခုကို ဖော်ပြရန် အသုံးပြုသော နာမည် သို့မဟုတ် ကုဒ်။
pipeline()Function: Hugging Face Transformers library မှာ ပါဝင်တဲ့ လုပ်ဆောင်ချက်တစ်ခုဖြစ်ပြီး မော်ဒယ်တွေကို သီးခြားလုပ်ငန်းတာဝန်များ (ဥပမာ- စာသားခွဲခြားသတ်မှတ်ခြင်း၊ စာသားထုတ်လုပ်ခြင်း) အတွက် အသုံးပြုရလွယ်ကူအောင် ပြုလုပ်ပေးပါတယ်။- Instantiate: class တစ်ခုမှ object တစ်ခုကို ဖန်တီးခြင်း။
fill-maskPipeline: Mask filling လုပ်ငန်းအတွက် ဒီဇိုင်းထုတ်ထားသော pipeline။text-classificationPipeline: Text classification လုပ်ငန်းအတွက် ဒီဇိုင်းထုတ်ထားသော pipeline။- Head (Model Head): Transformer မော်ဒယ်၏ အဓိကကိုယ်ထည် (body) အပေါ်တွင် ထည့်သွင်းထားသော အပိုအစိတ်အပိုင်း (layer တစ်ခု သို့မဟုတ် နှစ်ခု) ဖြစ်ပြီး သီးခြားလုပ်ငန်း (task) တစ်ခုအတွက် မော်ဒယ်၏ output များကို ချိန်ညှိပေးသည်။ ဥပမာ- sequence classification အတွက် head သည် logits ကို ထုတ်ပေးသည်။
- Model Architecture: Model တစ်ခု၏ layers များနှင့် ၎င်းတို့ ချိတ်ဆက်ပုံကို ဖော်ပြသော ဒီဇိုင်းဖွဲ့စည်းပုံ။
CamembertTokenizer: CamemBERT model အတွက် သီးခြားထုတ်လုပ်ထားသော tokenizer class။CamembertForMaskedLM: Masked Language Modeling (MLM) အတွက် CamemBERT model class။Auto*Classes (e.g.,AutoTokenizer,AutoModelForMaskedLM): Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တွေဖြစ်ပြီး model အမည် (checkpoint name) ကို အခြေခံပြီး သက်ဆိုင်ရာ tokenizer သို့မဟုတ် model class ကို အလိုအလျောက် ရွေးချယ်ပေးသည်။ ၎င်းတို့သည် architecture-agnostic ဖြစ်သည်။- Architecture-agnostic: မော်ဒယ်၏ အောက်ခံ architecture ကို သီးခြားသိရှိထားရန် မလိုဘဲ အလုပ်လုပ်နိုင်သော သဘောတရား။ မတူညီသော architecture များကြား ပြောင်းလဲခြင်းကို လွယ်ကူစေသည်။
TFAuto*Classes (e.g.,TFAutoModelForMaskedLM): TensorFlow framework အတွက်Auto*classes များနှင့် တူညီသော လုပ်ဆောင်ချက်များရှိသည်။- Model Card: Hugging Face Hub တွင် မော်ဒယ်တစ်ခုစီအတွက် ပါရှိသော အချက်အလက်များပါသည့် စာမျက်နှာ။ ၎င်းတွင် မော်ဒယ်ကို မည်သို့လေ့ကျင့်ခဲ့သည်၊ မည်သည့် datasets များကို အသုံးပြုခဲ့သည်၊ ၎င်း၏ ကန့်သတ်ချက်များ၊ ဘက်လိုက်မှုများ (biases) နှင့် အသုံးပြုနည်းများ ပါဝင်သည်။
- Biases: Model တစ်ခု၏ ခန့်မှန်းချက်များတွင် ဒေတာ သို့မဟုတ် သင်္ချာဆိုင်ရာ အကြောင်းများကြောင့် ဖြစ်ပေါ်လာသော ဘက်လိုက်မှုများ။
Xet Storage Details
- Size:
- 14.9 kB
- Xet hash:
- 205c3802de3377fc311d4682fc970e73f5862f6d989824b57360db99e4cc1b4d
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.