0Pricing
Deep Learning Academy · درس

تكديس كتلة Transformer Encoder

انتباه مع شبكة أمامية وتطبيع

تكديس كتلة Transformer Encoder درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Building Block

A transformer is just one encoder block repeated. Learn the block and you understand the whole tower, from tiny models to giant ones.

Two Sub-Layers

Each block has two parts: a multi-head attention sub-layer, then a small feedforward network. Both wrapped with residuals and normalization.

Attention First

The block starts with self-attention, letting every token mix in context from the rest of the sequence before any further processing.

attn_out, _ = self.attn(x, x, x)

The Residual Connection

A residual adds the sub-layer's input back to its output. This shortcut lets gradients flow and keeps deep stacks trainable.

x = x + attn_out

Layer Normalization

After adding the residual, layer norm rescales each token's features to a stable distribution, steadying training across layers.

x = self.norm1(x)

The Feedforward Net

Next comes a position-wise feedforward network: expand to a wider hidden size, apply a nonlinearity, then project back down.

ff = nn.Sequential(nn.Linear(d, 4*d), nn.GELU(), nn.Linear(4*d, d))

Per-Token Processing

The feedforward layer treats each token independently. Attention shared information; this step refines each token on its own.

Second Residual and Norm

The feedforward output gets the same treatment: a residual add plus another layer norm, finishing the block.

x = self.norm2(x + ff(x))

Stack Them Deep

Stack many identical blocks and the model builds richer representations layer by layer. Depth is where transformer power comes from.

layers = nn.ModuleList([Block(d) for _ in range(N)])

Pre-Norm vs Post-Norm

Many modern models apply layer norm before each sub-layer instead of after. Pre-norm trains more stably in very deep stacks.

Use the Built-in

PyTorch gives you nn.TransformerEncoderLayer and nn.TransformerEncoder, so you can assemble a full stack in just a couple of lines.

layer = nn.TransformerEncoderLayer(d_model, nhead)
enc = nn.TransformerEncoder(layer, num_layers=6)

Quick Check

Let's review the parts of an encoder block.

Recap

You assembled an encoder block: attention, residual, norm, feedforward, residual, norm. Stack it deep and you have a transformer. Amazing work!

الأسئلة الشائعة

هل درس «تكديس كتلة Transformer Encoder» مجاني؟

نعم — نص درس «تكديس كتلة Transformer Encoder» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

ماذا ستتعلم في «تكديس كتلة Transformer Encoder»؟

انتباه مع شبكة أمامية وتطبيع تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟

لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تكديس كتلة Transformer Encoder»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟

نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الانتباه الذاتي: Query وKey وValue
  2. الضرب النقطي المُقاس ومتعدد الرؤوس
  3. الترميز الموضعي للترتيب
  4. تكديس كتلة Transformer Encoder
← العودة إلى Deep Learning Academy