ब्लॉग परिचय
- यह Sebastian Raschka की किताब "Build a Large Language Model (from Scratch)" पर आधारित ब्लॉग सीरीज़ की आठवीं पोस्ट है.
- इस पोस्ट में "trainable self-attention" को implement करने का तरीका बताया गया है.
GPT-प्रकार decoder-only transformer आधारित LLM कैसे काम करता है
- टेक्स्ट स्ट्रिंग को tokens में विभाजित किया जाता है, और हर token को vector sequence में map करके token embeddings बनाए जाते हैं.
- positional embeddings बनाकर input embedding sequence तैयार की जाती है.
- input embeddings का उपयोग करके हर token के लिए attention scores बनाए जाते हैं.
- attention scores को normalize करके attention weights बनाए जाते हैं.
- हर token के लिए context vectors बनाए जाते हैं.
Scaled dot-product attention mechanism
- attention scores की गणना के लिए input sequence को तीन matrices (query, key, value) में project किया जाता है.
- attention scores को normalize करके attention weights बनाए जाते हैं, और इन्हीं का उपयोग करके context vectors की गणना की जाती है.
- यह पूरी प्रक्रिया efficient matrix multiplication के माध्यम से की जाती है.
Matrices का उपयोग करके spaces के बीच projection
- matrices का उपयोग vectors को अलग-अलग dimensions वाले spaces में project करने के लिए किया जाता है.
- input embeddings को query, key, और value spaces में project करके attention scores की गणना की जाती है.
Attention scores का normalization
- attention scores को normalize करने के लिए softmax function का उपयोग किया जाता है.
- dimensions के square root से divide करके normalize किया जाता है, जिससे small gradient की समस्या हल होती है.
Context vectors बनाना
- attention weights का उपयोग करके हर token के context vectors की गणना की जाती है.
- input embeddings को value space में project किया जाता है, और attention weights के weighted sum से context vectors बनाए जाते हैं.
अगला चरण
- आगे causal self-attention और multi-head attention पर चर्चा की जाएगी.
- self-attention mechanism के "क्यों" पर भी आगे गहराई से विचार करने की योजना है.
निष्कर्ष
- यह ब्लॉग पोस्ट self-attention mechanism को समझने में मदद कर सकती है.
- अतिरिक्त प्रश्न या राय comments में छोड़ी जा सकती हैं.
अभी कोई टिप्पणी नहीं है.