рдЕрдм рд╣рдо NLP рдХреЗ рд╕рдмрд╕реЗ рдХреНрд░рд╛рдВрддрд┐рдХрд╛рд░реА рдЕрд╡рд┐рд╖реНрдХрд╛рд░реЛрдВ рдХреА рдУрд░ рдмрдврд╝рддреЗ рд╣реИрдВ тАФ
ЁЯЪА Transformers рдФрд░ BERT тАФ рдЬрд┐рдиреНрд╣реЛрдВрдиреЗ NLP рдХреА рджреБрдирд┐рдпрд╛ рдХреЛ рдкреВрд░реА рддрд░рд╣ рдмрджрд▓ рджрд┐рдпрд╛ рд╣реИред
ЁЯФ╢ 1. Transformers: Introduction
Transformer architecture 2017 рдореЗрдВ Google рдиреЗ рдкреЗрд╢ рдХрд┐рдпрд╛, рдкреЗрдкрд░:
ЁЯУД “Attention is All You Need” тАФ Vaswani et al.
рдЗрд╕рдиреЗ Recurrent Networks (RNN, LSTM) рдХреА dependency рдХреЛ рд╣рдЯрд╛ рджрд┐рдпрд╛ рдФрд░ NLP рдХреЛ рдкреВрд░реА рддрд░рд╣ рд╕реЗ revolutionize рдХрд░ рджрд┐рдпрд╛ред
ЁЯУР Transformer рдХреА Key Idea: Self-Attention
рд╣рд░ word sentence рдХреЗ рдмрд╛рдХреА рд╕рднреА words рдХреЗ context рдХреЛ рд╕рд╛рде рдореЗрдВ рд╕рдордЭрддрд╛ рд╣реИ, рди рдХрд┐ рдХреЗрд╡рд▓ рдкрд┐рдЫрд▓реЗ рд╢рдмреНрджреЛрдВ рдХреЛред
ЁЯФз Architecture Overview
Transformer рджреЛ рдореБрдЦреНрдп рд╣рд┐рд╕реНрд╕реЛрдВ рдореЗрдВ рдмрдВрдЯрд╛ рд╣реЛрддрд╛ рд╣реИ:
[Encoder] тЖТтЖТтЖТтЖТтЖТтЖТтЖТтЖТтЖТ [Decoder]
| Part | Role |
|---|---|
| Encoder | Input text рдХреЛ рд╕рдордЭрдирд╛ (e.g., sentence meaning) |
| Decoder | Output generate рдХрд░рдирд╛ (e.g., translation, caption) |
Note: BERT рд╕рд┐рд░реНрдл Encoder рдпреВрдЬрд╝ рдХрд░рддрд╛ рд╣реИ, GPT рд╕рд┐рд░реНрдл Decoderред
ЁЯФБ Self-Attention Mechanism
рд╣рд░ рд╢рдмреНрдж input рдореЗрдВ рдмрд╛рдХреА рд╕рднреА рд╢рдмреНрджреЛрдВ рд╕реЗ relate рдХрд░рддрд╛ рд╣реИ:
Sentence: "The cat sat on the mat"
"cat" тЖТ attends to "the", "sat", "mat" etc. via attention scores
ЁЯФв Attention Equation:

рдЬрд╣рд╛рдБ:
- Q: Query
- K: Key
- V: Value
- dk: Key vector dimension
тЪЩя╕П Transformer рдХреЗ Components:
| Component | Explanation |
|---|---|
| ЁЯФ╣ Multi-Head Attention | Parallel attention layers for better learning |
| ЁЯФ╣ Positional Encoding | Sequence order рдХреА рдЬрд╛рдирдХрд╛рд░реА add рдХрд░рддрд╛ рд╣реИ |
| ЁЯФ╣ Feedforward Network | Linear + non-linear layers |
| ЁЯФ╣ Layer Normalization | Stable training |
| ЁЯФ╣ Residual Connections | Gradient flow рдмрдирд╛рдП рд░рдЦрддрд╛ рд╣реИ |
ЁЯза 2. BERT: Bidirectional Encoder Representations from Transformers
ЁЯУД “BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding” тАУ Devlin et al., 2018
ЁЯОп рдореБрдЦреНрдп рдЙрджреНрджреЗрд╢реНрдп:
- Language Understanding тАФ Chatbots, Q&A, classification
ЁЯФз рдХреИрд╕реЗ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИ?
- BERT рдХреЗрд╡рд▓ Transformer Encoder architecture рдкрд░ рдЖрдзрд╛рд░рд┐рдд рд╣реИред
- рдпрд╣ рджреЛрдиреЛрдВ рддрд░рдл рдХреЗ context рдХреЛ рдПрдХ рд╕рд╛рде рдкрдврд╝рддрд╛ рд╣реИ тАФ рдЗрд╕рд▓рд┐рдП Bidirectional рд╣реИред
ЁЯУК Pretraining Tasks:
- Masked Language Modeling (MLM)
- Sentence рдореЗрдВ рдХреБрдЫ рд╢рдмреНрджреЛрдВ рдХреЛ mask рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдФрд░ model рдХреЛ predict рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИред
Input: "The [MASK] is shining" Output: "sun" - Next Sentence Prediction (NSP)
- рджреЛ sentences рджрд┐рдП рдЬрд╛рддреЗ рд╣реИрдВ тАФ model рдХреЛ рдпрд╣ predict рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИ рдХрд┐ рджреВрд╕рд░рд╛ sentence рдкрд╣рд▓реЗ рдХреЗ рдмрд╛рдж рдЖрддрд╛ рд╣реИ рдпрд╛ рдирд╣реАрдВред
ЁЯУж Pretrained BERT Models:
| Variant | Description |
|---|---|
bert-base-uncased | Lowercase English, 12 layers |
bert-large-uncased | 24 layers, large model |
DistilBERT | Lightweight, faster |
Multilingual BERT | 100+ languages |
ЁЯФз BERT Applications:
| Task | Example |
|---|---|
| тЬЕ Sentiment Analysis | “I love this product!” тЖТ Positive |
| ЁЯза Question Answering | “Where is Taj Mahal?” тЖТ “Agra” |
| тЬНя╕П Named Entity Recognition | “Barack Obama is from USA” тЖТ Person, Country |
| ЁЯТм Chatbots | Intent understanding |
| ЁЯУГ Text Classification | News, spam, legal docs |
ЁЯз░ Example: HuggingFace Transformers
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
model = BertModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("I love deep learning", return_tensors="pt")
outputs = model(**inputs)
ЁЯза Transformer vs BERT
| Aspect | Transformer | BERT |
|---|---|---|
| Type | General architecture | Pretrained NLP model |
| Structure | Encoder + Decoder | Only Encoder |
| Direction | Depends | Bidirectional |
| Application | Translation, captioning | Understanding, classification |
ЁЯУИ Transformers & BERT Impact
| Area | Impact |
|---|---|
| ЁЯУЪ Research | NLP рдХреЛ neural-level accuracy |
| ЁЯЧгя╕П Chatbots | Smarter conversations |
| ЁЯз╛ Legal/Medical | Automated document understanding |
| ЁЯза AI Models | Foundation for GPT, T5, RoBERTa, etc. |
ЁЯУЭ Practice Questions:
- Transformer architecture рдореЗрдВ self-attention рдХрд╛ рдХреНрдпрд╛ role рд╣реИ?
- BERT bidirectional рдХреНрдпреЛрдВ рд╣реИ?
- Masked Language Modeling рдХрд╛ рдорддрд▓рдм рдХреНрдпрд╛ рд╣реИ?
- BERT рдХрд┐рди NLP tasks рдХреЗ рд▓рд┐рдП use рд╣реЛрддрд╛ рд╣реИ?
- HuggingFace рд╕реЗ BERT рдХреИрд╕реЗ load рдХрд░рддреЗ рд╣реИрдВ?
ЁЯза Summary Table
| Term | Description |
|---|---|
| Transformer | Sequence model using attention mechanism |
| BERT | Bidirectional encoder for NLP tasks |
| MLM | Mask words and predict |
| NSP | Predict sentence relationship |
| Applications | Q&A, classification, chatbot, NER |


