Jab hum text ko tokenize karte hain, toh hum ek compression-granularity tradeoff kar rahe hote hain. Chhoti vocabulary (jaise, byte-level ke liye 256 tokens) har character ko alag se treat karti hai. Badi vocabulary (100K+ tokens) common words ya phrases poore ke poore ek hi token mein represent kar sakti hai.
YEH kyun matter karta hai:
Sequence length directly transformer compute ko impact karti hai: O(n2d) self-attention ke liye, jahan n sequence length hai
Embedding table sizeV×d parameters hoti hai, jahan V vocabulary size hai
Token granularity affect karti hai ki model rare/unseen words pe kitna generalize kar sakta hai
Sequence length n, embedding dimension d, aur L transformer layers ke liye:
Self-attention cost per layer:Attention cost=O(n2d)
KYU: Attention mechanism QKT compute karta hai jo (n×d)×(d×n)=n×n hai. Phir attention-weighted values: (n×n)×(n×d)=n×d. n2 term dominate karta hai.
Total forward pass cost:Total cost≈L⋅n2d+L⋅nd2
n2d term (attention) aur nd2 term (feedforward) dono sequence length ke saath scale karte hain.
ISKA matlab: Sequence length n ko double karne se attention cost chaar guni ho jaati hai lekin feedforward cost sirf double hoti hai. Long documents ke liye, attention dominate karta hai.
Badi vocab jeetati hai agar:extra embedding params(Vl−Vs)d<attention memory savings(ns2−nl2)d⋅batch count
YEH formula kyun: Left side badi vocabulary ka permanent parameter overhead hai. Right side chhoti sequences se per-batch activation memory savings hai. Agar aap bahut saare batches process karte ho (training, high-throughput inference), toh right side accumulate hoti hai aur left ko outweigh kar sakti hai.
Chhoti vocabulary → lambi sequences (zyada attention cost) lekin kam embedding parameters. Badi vocabulary → chhoti sequences (kam attention cost) lekin zyada embedding parameters. Yeh ek resource allocation decision hai.
Attention cost ke liye vocab size se sequence length zyada kyun matter karta hai?
Attention cost O(n2d) hai jahan n sequence length hai. Sequence length double karne se attention cost chaar guni ho jaati hai. Embedding cost sirf O(V×d) hai, vocab size V mein linear hai.
Embedding table parameter count ka formula kya hai?
Embedding parameters = V×d jahan V vocabulary size hai aur d embedding dimension hai. GPT-2 small ke liye (V=50257, d=768), yeh 38.6M parameters hai.
Character-level models vocabulary tradeoff kyun solve nahi karte?
Woh embedding table cost eliminate karte hain lekin sequence length explode ho jaati hai (8-10x lambi). Attention O(n2) hai, isliye compute ~64x badh jaata hai. Tradeoff sirf parameters se compute pe shift ho jaata hai.
Badi vocabulary resources kab bachati hai?
Jab (Vl−Vs)d<(ns2−nl2)d×batch count ho. Extra embedding params ko bahut saare batches ke accumulated attention memory savings se outweigh hona chahiye.
Code models vs. general text ke liye typical vocabulary size kya hai?
Code models 50K-100K use karte hain (bahut saare unique identifiers). General text 32K-50K use karta hai. Code ko function/variable names ko bahut saare tokens mein split hone se bachane ke liye badi vocab chahiye.
Vocabulary mein frequency ke hisaab se bottom 10% kyun important hai?
Rare tokens (bottom 10%) ko good embeddings ke liye training mein phir bhi 50-100+ baar aana chahiye. Warna aap noisy embeddings pe parameters waste karte ho jo generalize nahi karte. Yeh vocab size choice guide karta hai.
Recall Ek 12-saal ke bacche ko explain karo
Imagine karo tum ek dost ko text kar rahe ho, lekin tumhare paas sirf ek limited "dictionary" of pre-approved text shortcuts hai.
Chhoti dictionary (256 shortcuts): Tum sirf individual letters bhej sakte ho jaise "h", "e", "l", "o". "hello" kehne ke liye tum 5 messages bhejte ho. Yeh slow hai!
Medium dictionary (32,000 shortcuts): Tumhare paas common words ke shortcuts hain. "hello" ek shortcut hai, "how" doosra hai, "are" teesra hai. Ab "hello how are you" sirf 4 shortcuts hai. Kitna fast!
Huge dictionary (200,000 shortcuts): Tumhare paas poore phrases ke shortcuts hain jaise "hello how are you doing today". Super fast! Lekin ab tumhare phone ko 200,000 shortcuts memory mein store karne pad rahe hain. Yeh bahut space leta hai.
The tradeoff: Chhoti dictionary = BAHUT SAARE messages bhejne padte hain (slow). Huge dictionary = tumhara phone shortcuts se bhar jaata hai (memory khaata hai). Tum "goldilocks" size chahte ho: itne shortcuts ki fast ho, lekin itne nahi ki phone mein space na rahe.
AI models ke liye, "messages bhejna" aise hai jaise computer har token ko process karta hai. Zyada tokens = zyada kaam (especially kyunki computer ko har token ko baaki har token se compare karna padta hai, jo bahut slow ho jaata hai). Lekin shortcuts store karna (vocabulary) bhi memory leta hai. Toh hum ek size chunte hain jo task ke liye "just right" ho!