Thuta Learning
Local AI / Local LLM
BasicAIbeginner

Parameters, Tokens, နဲ့ Context Windows

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Parameters, Tokens, နဲ့ Context Windows concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram ကို ဖတ်ပြီး architecture ထဲမှာ data/request ဘယ်လိုစီးဆင်းသလဲ ခြေရာခံနိုင်ရန်
  • ကိုယ့် hardware/use case အတွက် ဘယ်လို ရွေးချယ်သင့်သလဲ ဆုံးဖြတ်နိုင်ရန်

နားလည်ထားရမယ့် အချက်

'7B' (သို့) '70B' လို model name တွေကို တွေ့ဖူးပြီး ဒီနံပါတ်ဟာ ဘာကို ဆိုလိုလဲ စဉ်းစားဖူးမှာပါ။ ဒါဟာ billions of parameters - training အချိန်မှာ ချိန်ညှိခံခဲ့ရတဲ့ model ထဲက ဂဏန်းတန်ဖိုးတစ်ခုချင်းစီရဲ့ အတိုကောက်ပါ။ 7B model မှာ ဒီတန်ဖိုးတွေ ၇ ဘီလီယံလောက်ရှိပြီး၊ 70B model မှာတော့ ၇၀ ဘီလီယံလောက်ရှိပါတယ်။

engine ကြီးရင် ကားမြန်တတ်သလို နံပါတ်ကြီးရင် model ပိုကောင်းတယ်လို့ ယူဆချင်စိတ်ရှိပေမယ့်၊ AI မှာ ဒီယူဆချက် မှန်ကန်ချက်နည်းပါတယ်။ model quality ဟာ တကယ်တော့ အချက်အများအပြားပေါင်းစပ်ပေါ်မူတည်ပါတယ် -

  • architecture (အစိတ်အပိုင်းတွေ ဘယ်လိုကွန်ရက်ချိတ်ထားလဲ)
  • train ခံရတဲ့ data
  • စိတ်ဝင်စားတဲ့ task အတွက် fine-tune အရည်အသွေး
  • quantize လုပ်ပုံ (နောက်ပိုင်းသင်ခန်းစာတွင်ဖော်ပြမည်)

data ကောင်းကောင်းနဲ့ သေချာ train လုပ်ထားတဲ့ model သေးလေးဟာ ဂရုမစိုက်ဘဲ train လုပ်ထားတဲ့ model ကြီးထက် ကောင်းနိုင်ပါတယ်၊ ဒါကြောင့် parameter count တစ်ခုတည်းဟာ ခန့်မှန်းချက်တစ်ခုသာဖြစ်ပြီး နောက်ဆုံးအဖြေ လုံးဝမဟုတ်ပါဘူး။

parameter နဲ့ သီးခြားစီ model တိုင်းဟာ token လို့ခေါ်တဲ့ chunk တွေနဲ့ text ကို ဖတ်ရေးပါတယ် - စကားလုံးတစ်လုံးလုံးလည်း မဟုတ်၊ အက္ခရာတစ်လုံးချင်းစီလည်း မဟုတ်ဘဲ အလယ်အလတ်လောက်ပါ။ tokenizer ဆိုတာ model process မလုပ်ခင် ခင်ဗျားစာသားကို ဒီ chunk တွေအဖြစ် ဖြတ်ပေးတဲ့ software ပါ။ model တိုင်းမှာ context window ရှိပါတယ် - တစ်ချိန်တည်းမှာ အာရုံစိုက်နိုင်တဲ့ token အများဆုံးအရေအတွက်ပါ။ ဒီ budget ကို ခင်ဗျားပေးလိုက်တာအားလုံးက share သုံးပါတယ် -

  • behavior သတ်မှတ်ပေးတဲ့ system prompt
  • ယခုချိန်ထိ conversation history အားလုံး
  • ခင်ဗျားရဲ့ message အသစ်

ဒါကြောင့် ရှည်လျားတဲ့ conversation တစ်ခုဟာ screen ပေါ်က ဘာမှ မဖျက်ရသေးပေမယ့် model ရဲ့ view ထဲကနေ message ဟောင်းတွေကို တစ်ဖြည်းဖြည်း တွန်းထုတ်ပစ်နိုင်ပါတယ်။

Token
model က text ကို process လုပ်တဲ့ chunk ငယ်လေးတစ်ခု - စကားလုံးတစ်လုံးလုံးလည်းမဟုတ်၊ အက္ခရာလည်းမဟုတ်ဘဲ အလယ်အလတ်ပါ။
Tokenizer
model ထဲသို့ မဝင်ခင် စာသားကို token အဖြစ် ဖြတ်ပေးတဲ့ software အပိုင်းပါ။
Context Window
model တစ်ခုက တစ်ချိန်တည်းမှာ အာရုံစိုက်နိုင်တဲ့ token အများဆုံး အရေအတွက်ပါ။
text
WHAT FILLS A CONTEXT WINDOW
---------------------------
CONTEXT WINDOW (fixed token budget, e.g. 8000 tokens)
-------------------------------------------------------
| system prompt   | conversation history | new message |
-------------------------------------------------------
  sets behavior      everything said so far   your latest
                                                  input

  all three share the SAME budget - if the total goes
  over the limit, the oldest history drops out of view

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

model နှစ်ခုကို download မလုပ်ခင် နှိုင်းယှဉ်နေတယ်ဆိုပါစို့ - 3B model တစ်ခုနဲ့ 13B model တစ်ခု။ ကြီးရင်ပိုကောင်းတယ်လို့ ယူဆပြီး 13B model ကိုပဲ ရွေးချင်စိတ်ရှိတတ်ပေမယ့်၊ task က ရိုးရှင်းရင် - ဥပမာ customer message တိုတိုလေးတွေကို category ခွဲတာလိုမျိုး - fine-tune ကောင်းကောင်းလုပ်ထားတဲ့ 3B model တစ်ခုက memory နည်းနည်းပဲသုံးဘဲ ခင်ဗျား hardware ပေါ်မှာ ပိုမြန်မြန် run နေရင်းနဲ့ တိကျမှုအတူတူပဲ ဖြေနိုင်ပါတယ်။

token နဲ့ context window ကို နားလည်ထားတာလည်း အလားတူ လက်တွေ့ကျပါတယ် - document ရှည်ရှည်တွေနဲ့ conversation ဆက်တိုက်ကို model ဆီ ပို့ပေးနေတဲ့ tool တစ်ခု တည်ဆောက်နေရင် ခင်ဗျား input က token ဘယ်လောက်စားလဲ ခန့်မှန်းသိထားဖို့ လိုပါတယ်၊ မဟုတ်ရင် conversation အလယ်မှာ context limit ကို ရောက်သွားပြီး model က ခင်ဗျားအရင်ပြောခဲ့တာတွေကို 'မေ့' နေတာ တွေ့ရမှာပါ။

အောက်က heuristic estimator ဟာ real tokenizer မဟုတ်ပါဘူး - real tokenizer တွေက trained vocabulary သုံးပါတယ် - ဒါပေမယ့် text တစ်ခုက budget ဘယ်လောက်စားလဲဆိုတာ လျင်မြန်ပြီး ခန့်မှန်းတဲ့ အသိတစ်ခု ပေးနိုင်ပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

python
def estimate_tokens(text):
    """Very rough heuristic only: about 1 token per 4 characters.
    Real tokenizers use trained subword vocabularies and do NOT
    work this way - this is just a fast mental-model estimate."""
    return max(1, round(len(text) / 4))


sentences = [
    "Hello, how are you today?",
    "Local AI keeps your data on your own device.",
    "ဒီနေ့ မိုးရွာနေတယ်။",
]

for s in sentences:
    tokens = estimate_tokens(s)
    print(f"'{s}' -> ~{tokens} tokens (chars={len(s)})")
You should see
heuristic estimator ဟာ character count ကို 4 နဲ့စား၍ token အရေအတွက်ကို ခန့်မှန်းပါတယ်။ Output အတိအကျမှာ - 'Hello, how are you today?' -> ~6 tokens (chars=25)
'Local AI keeps your data on your own device.' -> ~11 tokens (chars=44)
'ဒီနေ့ မိုးရွာနေတယ်။' -> ~5 tokens (chars=19)

၅ မိနစ် စမ်းကြည့်

sentences list ထဲကို ခင်ဗျားကိုယ်ပိုင်စာကြောင်းတစ်ကြောင်း (မြန်မာ (သို့) English) ထည့်ပြီး estimate_tokens ဘယ်လောက် ခန့်မှန်းလဲ ကြည့်ပါ။ ပြီးရင် divisor ၄ ကို ၃ ပြောင်းကြည့်ပြီး result ဘယ်လိုပြောင်းလဲသွားလဲ သတိပြုပါ။

သတိလေးတစ်ချက်

parameter count ကိုပဲ ကြည့်ပြီး model quality ကို ဆုံးဖြတ်ခြင်း - architecture, data, fine-tuning အားလုံး ပေါင်းစပ်ပေါ်မူတည်ပါတယ်

context window ရဲ့ budget ကို system prompt နဲ့ history ကလည်း share သုံးနေတာကို မေ့ပြီး message အရှည်ကြီးတွေ ပို့ခြင်း

Quiz: Model Quality ကို ဘာက ဆုံးဖြတ်လဲ

model တစ်ခုက ကောင်းတဲ့အဖြေ ပေးနိုင်မနိုင်ကို အဓိက ဘာက ဆုံးဖြတ်လဲ?

Hugging Face docs: TokenizersLocal AI / Local LLM

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • parameter count ကိုပဲ ကြည့်ပြီး model quality ကို ဆုံးဖြတ်ခြင်း - architecture, data, fine-tuning အားလုံး ပေါင်းစပ်ပေါ်မူတည်ပါတယ်
  • context window ရဲ့ budget ကို system prompt နဲ့ history ကလည်း share သုံးနေတာကို မေ့ပြီး message အရှည်ကြီးတွေ ပို့ခြင်း
  • Model (သို့) tool အသစ်တစ်ခုကို production/daily-use workflow ထဲ တိုက်ရိုက်မထည့်ခင် သေးငယ်တဲ့ scale နဲ့ အရင်စမ်းကြည့်ပါ။

လေ့ကျင့်ခန်း

sentences list ထဲကို ခင်ဗျားကိုယ်ပိုင်စာကြောင်းတစ်ကြောင်း (မြန်မာ (သို့) English) ထည့်ပြီး estimate_tokens ဘယ်လောက် ခန့်မှန်းလဲ ကြည့်ပါ။ ပြီးရင် divisor ၄ ကို ၃ ပြောင်းကြည့်ပြီး result ဘယ်လိုပြောင်းလဲသွားလဲ သတိပြုပါ။

You'll know it worked when: heuristic estimator ဟာ character count ကို 4 နဲ့စား၍ token အရေအတွက်ကို ခန့်မှန်းပါတယ်။ Output အတိအကျမှာ - 'Hello, how are you today?' -> ~6 tokens (chars=25) 'Local AI keeps your data on your own device.' -> ~11 tokens (chars=44) 'ဒီနေ့ မိုးရွာနေတယ်။' -> ~5 tokens (chars=19)

Parameters, Tokens, နဲ့ Context Windows | Thuta Learning