সব আর্টিকেল

Transformer Architecture: ChatGPT-র ভেতরে আসলে কী আছে

২০১৭ সালের একটা paper পুরো AI জগৎ বদলে দিয়েছে। 'Attention is All You Need' — এই architecture-ই আজকের সব LLM-এর foundation। সহজ ভাষায় বুঝুন।

R
Rezoan Sultan
লেখক
5 মিনিট পড়া
Transformer Architecture: ChatGPT-র ভেতরে আসলে কী আছে

২০১৭ সালের জুন মাসে Google-এর আটজন researcher একটা paper publish করেন — "Attention is All You Need"। সেই paper-এ যে architecture introduce হয়েছিল সেটাই আজকের ChatGPT, Claude, Gemini — সবকিছুর foundation।

আজ আমরা সেই Transformer architecture-এর ভেতরে যাব। Math-এর গভীরে না, কিন্তু intuition তৈরি করব।

আগে যা ছিল: RNN-এর সমস্যা

২০১৭-র আগে text processing-এর প্রধান architecture ছিল RNN (Recurrent Neural Network) এবং তার variants (LSTM, GRU)।

RNN একটা একটা করে word process করত:

"আমি ভাত খাই" 
→ আমি → ভাত → খাই

প্রতিটা step-এ আগের context মনে রাখার চেষ্টা করত।

সমস্যা:

  1. Sequential — Parallelize করা যেত না, slow training
  2. Long-range dependency — ১০০ word পরের context মনে রাখতে পারত না
  3. Vanishing gradients — Deep network train করা কঠিন

Transformer এই সব সমস্যা solve করল।

Core Idea: Attention

Transformer-এর সবচেয়ে গুরুত্বপূর্ণ concept — Attention Mechanism

Attention কী?

Simple কথায় — প্রতিটা word অন্য সব word-এর দিকে "তাকায়" এবং decide করে কোনটা কতটা important।

Example:

বাক্য: "ছেলেটা বাজারে গেল কারণ সে কিছু কিনতে চেয়েছিল।"

"সে" word-এ যখন model আসে, তখন attention কী করে?

  • "ছেলেটা" → high attention (এটাই reference)
  • "বাজারে" → low attention
  • "গেল" → medium
  • "কিনতে" → high (action context)

Attention score calculate হয় mathematically, কিন্তু intuition এটা।

Self-Attention

Same sentence-এর words একে অপরের দিকে attention দেয় — সেটাই self-attention।

প্রতিটা word তিনটা vector-এ convert হয়:

  • Query (Q) — "আমি কী খুঁজছি?"
  • Key (K) — "আমার কাছে কী আছে?"
  • Value (V) — "আমি কী contribute করব?"

Score = Query × Key (compatibility check) Output = Score × Value (weighted contribution)

এই calculation এ data-এ pattern automatically emerge হয়।

Multi-Head Attention

একটা attention head একটা pattern শিখে। কিন্তু language-এ অনেক patterns আছে:

  • Grammatical relationships (subject-verb)
  • Semantic meanings
  • Co-references
  • Topic threads

Solution: ৮-৩২টা attention head parallel-এ চালানো। প্রতিটা head আলাদা pattern শেখে।

এই multiple "perspectives" মিলিয়ে পুরো understanding।

Transformer Block-এর Structure

একটা Transformer block-এর ভেতরে:

Input
  ↓
[Multi-Head Attention]
  ↓
Add & Normalize
  ↓
[Feed-Forward Network]
  ↓
Add & Normalize
  ↓
Output

এই block অনেকবার stack হয় (GPT-3-এ ৯৬, Claude-এ আরো বেশি)।

Positional Encoding

Transformer parallel process করে — মানে কে আগে কে পরে সেটা জানে না। তাই positional encoding add করা হয়।

প্রতিটা position-এর জন্য একটা unique vector যোগ হয় word embedding-এ। এতে model জানে কোন word কোথায়।

Encoder vs Decoder vs Encoder-Decoder

মূল Transformer paper-এ দুটো part ছিল:

Encoder

Input বুঝে। Bidirectional attention (সব word সবার দিকে দেখতে পারে)।

Use case: BERT — Text classification, sentiment analysis পরিচিত models: BERT, RoBERTa, DeBERTa

Decoder

Output generate করে। Causal attention (শুধু পেছনের word-গুলো দেখতে পারে)।

Use case: GPT — Text generation পরিচিত models: GPT-4, Claude, Llama

Encoder-Decoder

Both। Translation-এর জন্য আদর্শ।

পরিচিত models: T5, Original Transformer

আজকের most popular LLMs (GPT, Claude) সবই decoder-only architecture।

Scaling: কেন বড় Model বেশি Capable?

আজকের LLM-গুলো ছোট না:

  • GPT-3: ১৭৫ Billion parameters
  • GPT-4: ১.৮ Trillion (estimated)
  • Claude 3 Opus: ২ Trillion+ (estimated)
  • Gemini Ultra: ১.৫ Trillion (estimated)

কেন এত বড়?

Scaling Laws

OpenAI-র research দেখাল — model size, data, এবং compute বাড়ালে performance predictably বাড়ে।

Larger Model + More Data + More Compute = Better Capability

এই simple insight $200 Billion+ AI industry create করেছে।

Emergent Abilities

বড় হওয়ার পর model কিছু capability "emerge" করে যা ছোট model-এ ছিল না:

  • Multi-step reasoning
  • Code generation
  • Mathematical problem solving
  • Language translation (without explicit training)

এটাই LLM-এর সবচেয়ে fascinating দিক।

Training Process

একটা LLM train করার তিনটা stage:

Stage 1: Pre-training

Internet-এর প্রায় সব text data দিয়ে train। Task: "পরের word predict করো।"

Input: "ঢাকা বাংলাদেশের"
Predict: "রাজধানী"

এই simple task দিয়ে model language, reasoning, knowledge — সব শেখে।

Cost: Millions of dollars, months of compute।

Stage 2: Supervised Fine-tuning

Human-written examples দিয়ে refine। Helpful, accurate responses শেখানো।

Stage 3: RLHF (Reinforcement Learning from Human Feedback)

Human-রা multiple responses rank করেন। Model better responses produce করতে শেখে।

এই stage-ই ChatGPT-কে "useful chatbot" বানিয়েছিল।

কেন Transformer এত Successful?

কারণগুলো:

১. Parallelization: GPU-তে fast training ২. Long-range dependencies: Attention সব position দেখতে পারে ৩. Scalable: Bigger = Better (consistently) ৪. Universal: Text, image, audio, video — সব কাজে ৫. Transfer learning: Pre-trained model fine-tune করে সব use case

Limitations

Transformer perfect না:

  • Quadratic complexity — Long context (১M+ tokens) expensive
  • Hallucination — Confident-ly wrong answers
  • Knowledge cutoff — Training data পর্যন্ত
  • Reasoning limitations — Complex multi-step problems-এ struggle
  • Energy hungry — Environmental impact

Research চলছে এই limitations solve করতে — Mamba (state-space models), Linear attention, MoE architectures।

ভবিষ্যৎ: Beyond Transformer?

কিছু candidates যা Transformer-কে replace করতে পারে:

  • Mamba/SSM — Linear complexity
  • Mixture of Experts (MoE) — Larger but efficient (Mixtral, GPT-4 use করে)
  • Hybrid architectures — Transformer + অন্য কিছু

কিন্তু আগামী ৫-১০ বছর Transformer-ই dominant থাকবে most likely।

Practical Takeaway

আপনি যদি LLM use করেন বা build করেন:

১. Context window matters — যত বেশি token, তত expensive ২. Prompt structure-এ attention play করে — Important info early-তে দিন ৩. Few-shot examples work — Pattern শিখাতে পারেন instantly ৪. Temperature control — Output randomness ৫. Tokenization বুঝুন — Word না, token-এ measure হয়

পরের আর্টিকেলে

"LangChain বনাম Claude SDK: কোনটা কখন use করবেন" — practical implementation tutorial।

—রেজোয়ান

#Transformer#LLM#Architecture#Deep Learning
R
Rezoan Sultan

Applied Machine Learning Engineer এবং PhD candidate। বাংলায় AI শিক্ষাকে সহজলভ্য করার মিশনে কাজ করছেন।