• ट्रांसफॉर्मर मॉडल की संरचना और कार्य सिद्धांत को विज़ुअली समझाया गया है, और दिखाया गया है कि attention mechanism कैसे parallel learning और translation performance को बेहतर बनाता है
  • मॉडल encoder और decoder stack से बना है, और हर encoder में self-attention तथा feedforward neural network की दो परतें होती हैं
  • self-attention की गणना प्रक्रिया को vector और matrix स्तर पर चरण-दर-चरण समझाया गया है, और multi-head attention इसे इस तरह विस्तार देता है कि अलग-अलग representation space सीखे जा सकें
  • positional encoding, residual connection, layer normalization, और decoder की masked attention जैसे मुख्य घटकों को ठोस विज़ुअल रूप में दिखाया गया है
  • यह लेख ट्रांसफॉर्मर की बुनियादी अवधारणाओं को आसानी से समझने में मदद करने वाली एक प्रतिनिधि सामग्री है, और MIT·Stanford जैसे प्रमुख विश्वविद्यालयों के lectures और textbooks में भी उपयोग होता है

ट्रांसफॉर्मर अवलोकन

  • ट्रांसफॉर्मर एक attention-आधारित neural machine translation model है, जो कुछ कार्यों में मौजूदा Google Neural Machine Translation से बेहतर प्रदर्शन दिखाता है
    • इसका मुख्य लाभ यह है कि parallelization आसान है, और इसे Google Cloud TPU के reference model के रूप में recommend किया जाता है
  • मॉडल encoder और decoder stack से बना होता है, और हर encoder की संरचना समान होती है, लेकिन वे weights share नहीं करते
  • encoder input, self-attention layer से होकर context information को integrate करता है, और उसके बाद feedforward neural network से गुजरता है
  • decoder में encoder संरचना के अलावा encoder-decoder attention layer भी शामिल होती है, जो input sentence के प्रासंगिक हिस्सों पर ध्यान केंद्रित करती है

टेंसर फ्लो और embedding

  • input sentence को word embedding algorithm के जरिए हर शब्द के लिए 512-dimensional vector में बदला जाता है
  • encoder की हर layer समान आकार की vector list को input के रूप में लेकर process करती है, और sentence length को hyperparameter के रूप में set किया जाता है
  • feedforward layer हर position के vector को स्वतंत्र रूप से process करती है, इसलिए parallel computation संभव है

self-attention की अवधारणा

  • self-attention हर शब्द को वाक्य के दूसरे शब्दों का संदर्भ लेकर बेहतर representation सीखने में मदद करता है
    • उदाहरण: “The animal didn’t cross the street because it was too tired” में “it”, “animal” से संबंधित है
  • RNN में hidden state बनाए रखने के विपरीत, ट्रांसफॉर्मर self-attention के जरिए context information को integrate करता है

self-attention की गणना के चरण

  • हर word embedding से Query, Key, Value vector बनाए जाते हैं (dimension 64)
  • Query और Key के dot product से शब्दों के बीच relevance score की गणना की जाती है
  • score को √64 से भाग देने के बाद softmax लागू किया जाता है ताकि उसे probability distribution के रूप में normalize किया जा सके
  • हर Value vector पर softmax score को multiply करके उनका sum लेकर अंतिम attention output बनाया जाता है
  • वास्तविक implementation में यह प्रक्रिया matrix operations से की जाती है ताकि efficiency बढ़े

multi-head attention

  • कई attention heads (डिफ़ॉल्ट 8) का उपयोग करके अलग-अलग representation space सीखे जाते हैं
    • हर head के पास स्वतंत्र Q/K/V weight matrices होते हैं
  • कई heads के output को concat करने के बाद अतिरिक्त weight matrix WO से combine किया जाता है
  • इससे मॉडल context के अलग-अलग पहलुओं को एक साथ पकड़ सकता है

positional encoding

  • ट्रांसफॉर्मर क्रम को सीधे process नहीं करता, इसलिए हर word embedding में position vector जोड़ा जाता है
  • position vector को sine (sin) और cosine (cos) functions की मदद से बनाया जाता है, जो शब्दों के बीच relative distance information देता है
  • यह तरीका training data से लंबी sentences पर भी extend किया जा सकता है
  • 2020 update में दो signals को interleave करने का तरीका भी पेश किया गया था

residual connection और normalization

  • हर sublayer (self-attention, feedforward) पर residual connection और layer normalization लागू की जाती है
  • यह संरचना vanishing gradient को रोकने और training stability सुधारने में योगदान देती है

decoder संरचना

  • decoder, encoder output से Key/Value vector लेकर encoder-decoder attention करता है
  • masking के जरिए इसे भविष्य के शब्दों को refer करने से रोका जाता है
  • अंत में Linear layer और Softmax layer के जरिए शब्द probability distribution बनाई जाती है
    • उदाहरण: यदि vocabulary size 10,000 हो, तो हर output vector को 10,000-dimensional probability distribution में बदला जाता है

training और loss function

  • training के दौरान model की output probability distribution की तुलना correct distribution (one-hot encoding) से की जाती है
  • cross-entropy या KL divergence का उपयोग करके error की गणना की जाती है और backpropagation से weights adjust किए जाते हैं
  • beam search के जरिए कई candidate translations को बनाए रखकर accuracy बेहतर की जाती है

अनुवर्ती शोध और संदर्भ सामग्री

  • संबंधित papers: Attention Is All You Need, Training Tips for the Transformer Model, Self-Attention with Relative Position Representations आदि
  • implementation सामग्री: Tensor2Tensor package, Harvard NLP PyTorch guide, Colab Notebook
  • ट्रांसफॉर्मर बाद में LLM-book.com के expanded edition (Chapter 3) तक विकसित हुआ, जिसमें Multi-Query Attention और RoPE positional embedding जैसे नवीनतम models शामिल हैं

निष्कर्ष

  • ट्रांसफॉर्मर एक parallelizable attention-आधारित संरचना है, जो आधुनिक deep learning के मुख्य मॉडलों में स्थापित हो चुका है
  • यह लेख ट्रांसफॉर्मर की संरचना, गणित और intuition को विज़ुअली समझाने वाली एक प्रतिनिधि सामग्री है, और Stanford·MIT·Harvard जैसे प्रमुख विश्वविद्यालयों के lectures में संदर्भ सामग्री के रूप में उपयोग होता है

अभी कोई टिप्पणी नहीं है.

अभी कोई टिप्पणी नहीं है.