COE 592Lecture 02المحاضرة 02Referenceالمرجع
Reference sheetالورقة المرجعية
Neural network fundamentals compressed onto one page: the definitions, formulas and numbers to have in your head before a quiz or exam.محاضرة «أساسيات الشبكات العصبية» مضغوطة في صفحة واحدة: التعريفات والمعادلات والأرقام التي يجب أن تكون حاضرة في ذهنك قبل الاختبار القصير أو الامتحان.
Vocabulary and the two countsالمفردات والعددان
Parameters are stored (flash), activations are computed per input (SRAM). A network fits a microcontroller only when both fit: the STM32F746 has 320 kB SRAM and 1 MB flash, and ResNet-50's 25.6 M parameters are about 100 MB in fp32. Part 01: Neurons and linear layers
المعاملات تُخزَّن (flash)، والتفعيلات تُحسب لكل مدخل (SRAM). لا تناسب الشبكة متحكمًا دقيقًا إلا إذا ناسبه الاثنان معًا: المتحكم STM32F746 فيه 320 kB من SRAM و1 MB من flash، بينما معاملات ResNet-50 البالغة 25.6 M تشغل نحو 100 MB بصيغة fp32. الجزء 01: الخلايا العصبية والطبقات الخطية
| Diagram elementعنصر الرسم | Namesالأسماء | Behaviourالسلوك | Memoryالذاكرة |
|---|---|---|---|
| Edgeالحافة | Synapse, weight, parameterمشبك عصبي، وزن، معامل | Stored after training, one per connectionتُخزَّن بعد التدريب، واحدة لكل اتصال | Flash |
| Nodeالعقدة | Neuron, feature, activationخلية عصبية، سمة، تفعيل | Recomputed for every input, one per computed unitيُعاد حسابها لكل مدخل، واحدة لكل وحدة محسوبة | SRAM |
| Biasالانحياز | One per neuron, never per edgeواحد لكل خلية عصبية، وليس لكل حافة أبدًا | Stored, counted with the weightsيُخزَّن، ويُعدّ مع الأوزان | Flash |
| Widthالعرض | Size of a hidden layerحجم الطبقة المخفية | Goodfellow, Bengio and Courville | |
| Depthالعمق | Number of layers in the chain, input row not countedعدد الطبقات في السلسلة، دون عدّ صف المدخل | 5-4-3-2 is a 3-layer network, 2 hiddenالشبكة 5-4-3-2 شبكة من 3 طبقات، منها 2 مخفيتان |
Fully connected layer and MLPالطبقة كاملة الاتصال وشبكة MLP
Shapes and countsالأشكال والأعداد
- X
- (n, c_i)
- W
- (c_o, c_i)
- b
- (c_o,)
- Y
- (n, c_o)
- Parametersالمعاملات
- c_o × c_i + c_o
- Activations per sampleالتفعيلات لكل عيّنة
- Sum of layer widths, plus the input if budgeting memoryمجموع عروض الطبقات، ويُضاف المدخل عند حساب ميزانية الذاكرة
| Networkالشبكة | Weightsالأوزان | Biasesالانحيازات | Parametersالمعاملات | Activations per sampleالتفعيلات لكل عيّنة |
|---|---|---|---|---|
| Slide 4, 5-4-3-2الشريحة 4، 5-4-3-2 | 20 + 12 + 6 = 38 | 4 + 3 + 2 = 9 | 47 | 9 |
| Slide 5, 5 to 3الشريحة 5، من 5 إلى 3 | 15 | 3 | 18 | 3 |
| Slide 7, 5 to 3 to 2الشريحة 7، من 5 إلى 3 إلى 2 | 15 + 6 = 21 | 3 + 2 = 5 | 26 | 5 (10 with inputs)5 (10 مع المدخلات) |
| CS231n, 3-4-4-1CS231n، 3-4-4-1 | 12 + 16 + 4 = 32 | 4 + 4 + 1 = 9 | 41 | 9 |
| MNIST 784 to 128MNIST من 784 إلى 128 | 100,352 | 128 | 100,480 (392 KiB fp32)100,480 (392 KiB بصيغة fp32) | 912 (7,296 at n = 8)912 (7,296 عند n = 8) |
Convolution shapes and output sizeأشكال الالتفاف وحجم المخرج
Each output sees only the k inputs in its receptive field (sparse) and the same filter is reused at every position (weight sharing), so the parameter count never depends on h_i or w_i. Part 02: Convolution layers
كل مخرج لا يرى إلا المدخلات الـ k الواقعة في حقله الاستقبالي (اتصال متناثر sparse)، والمرشّح نفسه يُعاد استخدامه في كل موضع (مشاركة الأوزان weight sharing)، لذلك لا يعتمد عدد المعاملات أبدًا على h_i أو w_i. الجزء 02: طبقات الالتفاف
| Tensorالموتر | Fully connectedكاملة الاتصال | 1D convالتفاف أحادي البعد | 2D convالتفاف ثنائي البعد |
|---|---|---|---|
| X | (n, c_i) | (n, c_i, w_i) | (n, c_i, h_i, w_i) |
| Y | (n, c_o) | (n, c_o, w_o) | (n, c_o, h_o, w_o) |
| W | (c_o, c_i) | (c_o, c_i, k_w) | (c_o, c_i, k_h, k_w) |
| b | (c_o,) | (c_o,) | (c_o,) |
| h_ih_i | kk | ss | pp | Arithmeticالحساب | h_oh_o |
|---|---|---|---|---|---|
| 4 | 3 | 1 | 0 | (4 - 3)/1 + 1 | 2 |
| 4 | 2 | 2 | 0 | (4 - 2)/2 + 1 | 2 |
| 5 | 3 | 1 | 1 | (5 + 2 - 3)/1 + 1 | 5 |
| 32 | 5 | 1 | 0 | (32 - 5)/1 + 1 | 28 |
| 32 | 5 | 1 | 2 | (32 + 4 - 5)/1 + 1 | 32 |
| 32 | 5 | 2 | 2 | floor(31/2) + 1 | 16 |
| 8 | 3 | 2 | 0 | floor(5/2) + 1 | 3, not 3.53 وليس 3.5 |
| 224 | 7 | 2 | 3 | floor(223/2) + 1 | 112 |
Slide 15 worked numbersأرقام الشريحة 15 محسوبة
- Setupالإعداد
- X (1, 2, 4, 4), W (1, 2, 2, 2), stride 2, no padding, no biasX (1, 2, 4, 4)، W (1, 2, 2, 2)، خطوة 2، بلا حشو، بلا انحياز
- Output sizeحجم المخرج
- (4 - 2)/2 + 1 = 2, so 2 × 2(4 - 2)/2 + 1 = 2، إذن 2 × 2
- Top leftأعلى اليسار
- channel 1 2·1 + 1·2 + 1·1 + 2·2 = 9, channel 2 1·5 + 2·6 + 2·5 + 1·6 = 33, sum 42القناة 1: 2·1 + 1·2 + 1·1 + 2·2 = 9، القناة 2: 1·5 + 2·6 + 2·5 + 1·6 = 33، المجموع 42
- Top rightأعلى اليمين
- channel 1 21, channel 2 45, sum 66القناة 1: 21، القناة 2: 45، المجموع 66
- Resultالنتيجة
- [[42, 66], [42, 66]]
- Stride 1 insteadبخطوة 1 بدلًا من ذلك
- 3 × 3 output, middle column 15 + 39 = 54, one row 42, 54, 66مخرج 3 × 3، العمود الأوسط 15 + 39 = 54، وصف واحد 42, 54, 66
Parameter counts, conv versus FCعدد المعاملات: الالتفاف مقابل الطبقة كاملة الاتصال
| Layerالطبقة | Arithmeticالحساب | Parametersالمعاملات | Depends on image size?هل يعتمد على حجم الصورة؟ |
|---|---|---|---|
| Conv2D 16 filters 5 × 5, 3 to 16Conv2D بـ 16 مرشحًا 5 × 5، من 3 إلى 16 | 16 × 3 × 5 × 5 + 16 | 1216 | Noلا |
| Same layer, 3 × 3 kernelsالطبقة نفسها بنوى 3 × 3 | 16 × 3 × 9 + 16 | 448 | Noلا |
| Same layer, 32 filtersالطبقة نفسها بـ 32 مرشحًا | 32 × 75 + 32 | 2432 | Noلا |
| Conv2D 128 filters 3 × 3, 64 to 128Conv2D بـ 128 مرشحًا 3 × 3، من 64 إلى 128 | 128 × 64 × 9 + 128 | 73,856 | Noلا |
| AlexNet conv1, 96 filters 11 × 11, 3 to 96الطبقة conv1 في AlexNet، 96 مرشحًا 11 × 11، من 3 إلى 96 | 96 × 3 × 121 + 96 | 34,944 (105.7 M unshared)34,944 (105.7 M دون مشاركة الأوزان) | Noلا |
| FC 32 × 32 × 3 = 3072 to 16كاملة الاتصال 32 × 32 × 3 = 3072 إلى 16 | 3072 × 16 + 16 | 49,168 | Yesنعم |
| FC 64 × 64 × 3 = 12,288 to 16كاملة الاتصال 64 × 64 × 3 = 12,288 إلى 16 | 12,288 × 16 + 16 | 196,624 | Yesنعم |
Padding, stride and receptive fieldالحشو والخطوة والحقل الاستقبالي
Padding and stride change h_o × w_o, hence activations and MACs, and never the parameter count. Part 03: Padding, stride and grouped convolution
الحشو والخطوة يغيّران h_o × w_o، وبالتالي عدد التفعيلات وعمليات MAC، ولا يغيّران عدد المعاملات أبدًا. الجزء 03: الحشو والخطوة والالتفاف المجمّع
| Modeالنمط | Ruleالقاعدة | Row 0الصف 0 |
|---|---|---|
| Zero (default)الصفري (الافتراضي) | Fill the border with 0املأ الإطار بالقيمة 0 | 0 0 0 0 0 0 0 |
| Reflectionالانعكاس | Mirror across the edge, edge value not repeated, needs p < input sizeمرآة حول الحافة دون تكرار قيمة الحافة، ويتطلب p أصغر من حجم المدخل | 9 8 7 8 9 8 7 |
| Replicationالتكرار | Repeat the nearest edge value outwardكرّر أقرب قيمة على الحافة نحو الخارج | 1 1 1 2 3 3 3 |
| Constantالثابت | Fill the border with a chosen value vاملأ الإطار بقيمة مختارة v | v v v v v v v |
| LL | All stride 1كل الخطوات 1 | First layer stride 2خطوة 2 في الطبقة الأولى | Every layer stride 2خطوة 2 في كل طبقة |
|---|---|---|---|
| 1 | 3 | 3 | 3 |
| 2 | 5 | 7 | 7 |
| 3 | 7 | 11 | 15 |
| 4 | 9 | 15 | 31 |
Grouped and depthwise convolutionالالتفاف المجمّع والالتفاف العمقي
| Layerالطبقة | W shapeشكل W | Weightsالأوزان | Weights + biasesالأوزان مع الانحيازات | Fewer than standardأقل من القياسي بـ |
|---|---|---|---|---|
| Standard, g = 1قياسي، g = 1 | (64, 64, 3, 3) | 36,864 | 36,928 | 1× |
| Grouped, g = 2مجمّع، g = 2 | (64, 32, 3, 3) | 18,432 | 18,496 | 2× |
| Grouped, g = 4مجمّع، g = 4 | (64, 16, 3, 3) | 9,216 | 9,280 | 4× |
| Grouped, g = 8مجمّع، g = 8 | (64, 8, 3, 3) | 4,608 | 4,672 | 8× |
| Depthwise, g = 64عمقي، g = 64 | (64, 1, 3, 3) | 576 | 640 | 64× |
| Depthwise + 1 × 1 pointwiseعمقي مع نقطي 1 × 1 | (64, 1, 3, 3) + (64, 64, 1, 1) | 576 + 4,096 = 4,672 | 4,800 | 7.9× |
Depthwise separable cost ratio (Howard et al.): 1/N + 1/D_K², so 1/64 + 1/9 ≈ 0.127, about 7.9× cheaper. On a 56 × 56 map: 115.6 M MACs standard against 14.7 M separable. A depthwise layer never mixes channels; the 1 × 1 pointwise layer (c_o · c_i weights) restores mixing. Grouped convolution does not change h_o, w_o or c_o.
نسبة تكلفة الالتفاف العمقي القابل للفصل (depthwise separable) بحسب Howard et al.: 1/N + 1/D_K²، أي 1/64 + 1/9 ≈ 0.127، فهو أرخص بنحو 7.9×. على خريطة 56 × 56: 115.6 M عملية MAC للالتفاف القياسي مقابل 14.7 M للقابل للفصل. الطبقة العمقية لا تمزج القنوات أبدًا، وطبقة 1 × 1 النقطية (pointwise) (بعدد أوزان c_o · c_i) تعيد المزج. الالتفاف المجمّع لا يغيّر h_o ولا w_o ولا c_o.
Poolingالتجميع (Pooling)
A fixed summary of a window inside each channel independently: spatial size drops, channel count unchanged, zero parameters. Part 04: Pooling and CNN features
ملخص ثابت لنافذة داخل كل قناة على حدة: الحجم المكاني يقل، وعدد القنوات لا يتغير، وعدد المعاملات صفر. الجزء 04: التجميع وسمات شبكات CNN
| Max poolingالتجميع الأقصى | Average poolingالتجميع المتوسط | |
|---|---|---|
| What it returnsما يُرجعه | Largest value in the windowأكبر قيمة في النافذة | Mean of the windowمتوسط النافذة |
| Shift by one cellالإزاحة بخلية واحدة | Usually unchanged (approximate translation invariance)لا يتغير في الغالب (ثبات تقريبي أمام الإزاحة) | Changes slightlyيتغير قليلًا |
| Gradientالتدرج | Routed to the argmax cell onlyيُوجَّه إلى خلية argmax فقط | 1/F² to every cell1/F² لكل خلية |
| Typical placeالموضع المعتاد | Inside the trunk after a conv blockداخل الجذع بعد كتلة التفاف | Global average pool as the headتجميع متوسط شامل في رأس الشبكة |
| Slide 22 slice, F = 2, S = 2مقطع الشريحة 22، F = 2، S = 2 | [[6, 8], [3, 4]] | [[3.25, 5.25], [2, 2]] |
| Input, F, Sالمدخل، F، S | Arithmeticالحساب | Outputالمخرج |
|---|---|---|
| 224, F = 2, S = 2 | (224 - 2)/2 + 1 | 112, activations 3,211,264 to 802,816112، والتفعيلات من 3,211,264 إلى 802,816 |
| 224, F = 3, S = 2 | (224 - 3)/2 + 1 = 111.5 | 111 floored, 112 with ceil_mode111 بالتقريب للأسفل، و112 مع ceil_mode |
| 55, F = 3, S = 2 (AlexNet) | (55 - 3)/2 + 1 | 27 |
| 56 × 56 × 128, F = 3, S = 2 | (56 - 3)/2 + 1 = 27.5 | 27 × 27 × 128 |
| 4, F = 3, S = 2 | (4 - 3)/2 + 1 = 1.5 | 1 × 1, value [[7]]1 × 1، والقيمة [[7]] |
Feature hierarchy and full network countsهرمية السمات وعدّ الشبكة كاملة
| Tierالمستوى | Layersالطبقات | Responds toتستجيب لـ | Receptive fieldالحقل الاستقبالي |
|---|---|---|---|
| Lowمنخفض | First conv layersطبقات الالتفاف الأولى | Oriented edges, bars, blobsحواف موجّهة، وأشرطة، وبقع | 3 × 3 to 11 × 11 px3 × 3 إلى 11 × 11 بكسل |
| Midمتوسط | Middle layersالطبقات الوسطى | Eyes, wheels, tusks, chair legsعيون، وعجلات، وأنياب، وأرجل كراسٍ | tens of pixelsعشرات البكسلات |
| Highمرتفع | Deepest layersأعمق الطبقات | Whole faces, cars, elephants, chairsوجوه كاملة، وسيارات، وأفيال، وكراسٍ | most of the imageمعظم الصورة |
| Layerالطبقة | Outputالمخرج | Parametersالمعاملات |
|---|---|---|
| inputالمدخل | 32 × 32 × 3 | 0 |
| conv 16 × 5 × 5 × 3, pad 2التفاف 16 × 5 × 5 × 3، حشو 2 | 32 × 32 × 16 | 1216 |
| max pool 2, stride 2تجميع أقصى 2، خطوة 2 | 16 × 16 × 16 | 0 |
| conv 20 × 5 × 5 × 16, pad 2التفاف 20 × 5 × 5 × 16، حشو 2 | 16 × 16 × 20 | 8020 |
| max pool 2, stride 2تجميع أقصى 2، خطوة 2 | 8 × 8 × 20 | 0 |
| conv 20 × 5 × 5 × 20, pad 2التفاف 20 × 5 × 5 × 20، حشو 2 | 8 × 8 × 20 | 10,020 |
| max pool 2, stride 2تجميع أقصى 2، خطوة 2 | 4 × 4 × 20 | 0 |
| softmax 320 to 10softmax من 320 إلى 10 | 10 | 3210 |
| Totalالمجموع | 22,466 |
| Layerالطبقة | Outputالمخرج | Parametersالمعاملات |
|---|---|---|
| inputالمدخل | 64 × 64 × 3 | 0 |
| conv_1_1, 10 × 3 × 3, validconv_1_1، 10 × 3 × 3، بلا حشو (valid) | 62 × 62 × 10 | 280 |
| conv_1_2, 10 × 3 × 3, validconv_1_2، 10 × 3 × 3، بلا حشو (valid) | 60 × 60 × 10 | 910 |
| max_pool_1, 2, stride 2max_pool_1، 2، خطوة 2 | 30 × 30 × 10 | 0 |
| conv_2_1 | 28 × 28 × 10 | 910 |
| conv_2_2 | 26 × 26 × 10 | 910 |
| max_pool_2 | 13 × 13 × 10 | 0 |
| flatten 1690, dense 10تسطيح (flatten) 1690، طبقة كثيفة 10 | 10 | 16,910 |
| Totalالمجموع | 19,920 |
Only the first fully connected layer's count depends on image size (320 inputs in ConvNetJS, 1690 in Tiny VGG). The SRAM high-water mark is the largest activation tensor, in Tiny VGG the 62 × 62 × 10 = 38,440 output of the first conv.
عدد معاملات أول طبقة كاملة الاتصال فقط هو الذي يعتمد على حجم الصورة (320 مدخلًا في ConvNetJS، و1690 في Tiny VGG). أعلى استهلاك لـ SRAM هو أكبر موتر تفعيلات، وفي Tiny VGG هو مخرج أول طبقة التفاف 62 × 62 × 10 = 38,440.
Batch normalizationتطبيع الدفعة (Batch normalization)
Inputs that are off-centre force a large bias; inputs with different scales force W entries to span magnitudes. BN standardizes each feature over the batch with a differentiable map inside the network. Part 05: Normalization
المدخلات غير المتمركزة حول الصفر تفرض انحيازًا (bias) كبيرًا، والمدخلات ذات المقاييس المختلفة تجبر عناصر W على أن تمتد عبر رتب مقادير مختلفة. يقوم BN بتوحيد مقياس كل سمة عبر الدفعة بتحويل قابل للاشتقاق داخل الشبكة. الجزء 05: التطبيع
Shapes and defaults for a fully connected inputالأشكال والقيم الافتراضية لمدخل طبقة كاملة الاتصال
- x, x_hat, y
- N × D
- mu, sigma squared
- D, computed over the batch axis ND، تُحسب على محور الدفعة N
- gamma, beta
- D, the only learned parametersD، وهما المعاملان الوحيدان المتعلَّمان
- eps, momentum (PyTorch)
- 1e-5, 0.1
- Identity recoveryاستعادة الدالة المحايدة
- gamma = sqrt(sigma² + eps), beta = mu
- BatchNorm2d over C channelsBatchNorm2d على C قناة
- 2C parameters, running mean and variance are buffers2C معامل، والمتوسط والتباين المتحركان مخازن (buffers) وليسا معاملات
Normalization axesمحاور التطبيع
| Normalizationالتطبيع | Averages overيحسب المتوسط على | mu, sigma shapeشكل mu وsigma | gamma, beta shapeشكل gamma وbeta | Same at train and test?هل هو نفسه في التدريب والاختبار؟ |
|---|---|---|---|---|
| BN, fully connectedBN، طبقة كاملة الاتصال | N | 1 × D | 1 × D | Noلا |
| BN, convolutionBN، التفاف | N, H, W | 1 × C × 1 × 1 | 1 × C × 1 × 1 | Noلا |
| Layer normتطبيع الطبقة | D (or C, H, W)D (أو C, H, W) | N × 1 | 1 × D on slide 35, per channel in Wu and He1 × D في الشريحة 35، ولكل قناة عند Wu وHe | Yesنعم |
| Instance normتطبيع النسخة | H, W | N × C × 1 × 1 | 1 × C × 1 × 1 | Yesنعم |
| Group norm, G groupsتطبيع المجموعات، G مجموعة | H, W and C/G channelsH وW وC/G قناة | N × G × 1 × 1 | 1 × C × 1 × 1 | Yesنعم |
| Normالتطبيع | mu shapeشكل mu | Values per meanعدد القيم لكل متوسط |
|---|---|---|
| BN | 1 × 64 × 1 × 1 | 8 × 32 × 32 = 8192 |
| LN | 8 × 1 × 1 × 1 | 64 × 32 × 32 = 65,536 |
| IN | 8 × 64 × 1 × 1 | 32 × 32 = 1024 |
| GN, G = 32 | 8 × 32 × 1 × 1 | 2 × 1024 = 2048 |
| Rowالصف | Feature 1السمة 1 | Feature 2السمة 2 | Feature 3السمة 3 |
|---|---|---|---|
| After ReLUبعد ReLU | 3, 1, 3, 2 | 0, 2, 3, 0 | 0, 5, 2, 0 |
| Mean (divide by N = 4)المتوسط (القسمة على N = 4) | 2.25 | 1.25 | 1.75 |
| Variance (biased)التباين (المتحيز) | 0.6875 | 1.6875 | 4.1875 |
| Standard deviationالانحراف المعياري | 0.829 | 1.299 | 2.046 |
| x_hat | 0.905, -1.508, 0.905, -0.302 | -0.962, 0.577, 1.347, -0.962 | -0.855, 1.588, 0.122, -0.855 |
| gamma, beta | 2, 0 | 3, 0 | -1, 1 |
| y | 1.81, -3.02, 1.81, -0.60 | -2.89, 1.73, 4.04, -2.89 | 1.86, -0.59, 0.88, 1.86 |
| Check: mean beta, variance gamma²تحقق: المتوسط beta، والتباين gamma² | 0, 4 | 0, 9 | 1, 1 |
Activation functionsدوال التفعيل
Without a nonlinearity stacked linear layers collapse into one. On an MCU the two questions are: does it need an exponential, and is the output bounded? Part 06: Activations and transformers
بدون دالة غير خطية تنهار الطبقات الخطية المكدّسة إلى طبقة واحدة. على المتحكم الدقيق (MCU) السؤالان هما: هل تحتاج الدالة إلى أسّ (exponential)، وهل مخرجها محدود؟ الجزء 06: دوال التفعيل والمحوّلات
| Functionالدالة | Formulaالصيغة | Rangeالمدى | Derivativeالمشتقة | Needsتحتاج إلى | Noteملاحظة |
|---|---|---|---|---|---|
| Sigmoid | 1 / (1 + e^-x) | (0, 1) | s(1 - s), at most 0.25s(1 - s)، وأقصاها 0.25 | exp | Saturates both sidesتتشبّع من الجهتين |
| ReLU | max(0, x) | [0, inf) | 0 or 10 أو 1 | max | Default hidden unit, range must be calibrated for int8الوحدة المخفية الافتراضية، ويجب معايرة مداها لصيغة int8 |
| ReLU6 | min(max(0, x), 6) | [0, 6] | 1 on (0, 6), else 01 على (0, 6)، و0 فيما عدا ذلك | max, min | Fixed int8 grid, MobileNetV2شبكة int8 ثابتة، MobileNetV2 |
| Leaky ReLU | max(alpha x, x) | (-inf, inf) | alpha or 1alpha أو 1 | max | alpha = 0.01 defaultalpha = 0.01 افتراضيًا |
| Swish (SiLU) | x / (1 + e^-x) | [-0.278, inf) | s + x s(1 - s) | exp | Beats ReLU on deep models, costly on MCUsتتفوق على ReLU في النماذج العميقة، ومكلفة على المتحكمات الدقيقة |
| Hard swish | x ReLU6(x + 3) / 6 | [-0.375, inf) | 0, (2x + 3)/6, or 10 أو (2x + 3)/6 أو 1 | clamp, multiplyتقييد (clamp) وضرب | Within 0.142 of swish, MobileNetV3لا تبعد عن swish بأكثر من 0.142، MobileNetV3 |
| tanh | 2 s(2x) - 1 | (-1, 1) | 1 - tanh² | exp | Zero centred, still saturatesمتمركزة حول الصفر، لكنها ما زالت تتشبّع |
| GELU | x Phi(x) | [-0.17, inf) | Phi(x) + x phi(x) | erf or tanherf أو tanh | BERT and GPT defaultالافتراضية في BERT وGPT |
| Activationدالة التفعيل | Rangeالمدى | Step size over 255 stepsحجم الخطوة على 255 خطوة |
|---|---|---|
| ReLU6 | [0, 6], fixed at design time[0, 6]، ثابت وقت التصميم | 6 / 255 = 0.0235 |
| ReLU, calibrated on dataReLU بمعايرة على البيانات | [0, 60] if one channel spikes[0, 60] إذا قفزت قناة واحدة | 60 / 255 = 0.235, ten times coarser60 / 255 = 0.235، أخشن بعشر مرات |
Transformer block and attentionكتلة المحوّل والانتباه
The encoder layer (Vaswani et al. 2017)طبقة المُرمِّز (Vaswani et al. 2017)
- Encoder layerطبقة المُرمِّز
- Multi-head attention, Add and Norm, position-wise FFN, Add and Norm, stacked N timesانتباه متعدد الرؤوس (multi-head attention)، ثم Add and Norm، ثم FFN موضعية، ثم Add and Norm، وتُكدَّس N مرة
- Add and Norm
- LayerNorm(x + Sublayer(x)), LayerNorm not BatchNorm because it needs no batch statisticsLayerNorm(x + Sublayer(x))، ونستخدم LayerNorm لا BatchNorm لأنه لا يحتاج إلى إحصاءات الدفعة
- Base hyperparametersالمعاملات الفائقة للنموذج الأساسي
- N = 6, d_model = 512, h = 8, d_k = d_v = 64, d_ff = 2048
- Positional encodingالترميز الموضعي
- PE(pos, 2i) = sin(pos / 10000^(2i / d_model)), cosine for odd indices, added before layer 1PE(pos, 2i) = sin(pos / 10000^(2i / d_model))، وجيب التمام (cosine) للمؤشرات الفردية، ويُضاف قبل الطبقة 1
- Decoder extrasإضافات فك الترميز
- Masked self-attention, then encoder-decoder attention (queries from decoder, keys and values from encoder)انتباه ذاتي مقنَّع (masked self-attention)، ثم انتباه بين المُرمِّز وفاك الترميز (الاستعلامات من فاك الترميز، والمفاتيح والقيم من المُرمِّز)
- Weights per base layerالأوزان في كل طبقة أساسية
- attention 4 × 512 × 512 = 1,048,576, FFN 2 × 512 × 2048 = 2,097,152, about 67% in the FFNالانتباه 4 × 512 × 512 = 1,048,576، وFFN 2 × 512 × 2048 = 2,097,152، أي نحو 67% منها في FFN
Shapes for N tokensالأشكال لـ N رمزًا
- Q, K
- N × d_k
- V
- N × d_v
- Q Kᵀ and its softmaxQ Kᵀ ودالة softmax عليه
- N × N
- Outputالمخرج
- N × d_v
- Learnedالمتعلَّم
- W_Q, W_K, W_V (and W_O); the N × N weights are recomputed per inputW_Q, W_K, W_V (وW_O)؛ أما الأوزان N × N فيُعاد حسابها لكل مدخل
| d_kd_k | Unscaledدون تقييس | softmax unscaledsoftmax دون تقييس | softmax scaledsoftmax بعد التقييس |
|---|---|---|---|
| 4 | (2, 0, -2) | (0.867, 0.117, 0.016) | (0.665, 0.245, 0.090) |
| 64 | (8, 0, -8) | (1.000, 0.000, 0.000) | (0.665, 0.245, 0.090) |
| 512 | (22.6, 0, -22.6) | (1.000, 0.000, 0.000) | (0.665, 0.245, 0.090) |
| Tokens Nعدد الرموز N | Entriesالعناصر | Memoryالذاكرة |
|---|---|---|
| 64 | 4,096 | 16 KB |
| 256 | 65,536 | 256 KB |
| 1,024 | 1,048,576 | 4 MB |
| 4,096 | 16,777,216 | 64 MB |
Attention and FFN by handالانتباه وFFN يدويًا
Slide 43: keys k1 = (0, 0, 1), k2 = (2, 1, 0), k3 = (1, 0, -1), k4 = (0, 0, 1); values v1 = (20, 0, 0), v2 = (0, 0, 10), v3 = (0, 10, 0), v4 = (20, 10, 0). Shortcut: halve and truncate instead of dividing by sqrt(3), use 3^x instead of e^x.
الشريحة 43: المفاتيح k1 = (0, 0, 1) وk2 = (2, 1, 0) وk3 = (1, 0, -1) وk4 = (0, 0, 1)، والقيم v1 = (20, 0, 0) وv2 = (0, 0, 10) وv3 = (0, 10, 0) وv4 = (20, 10, 0). الاختصار المستخدم: نقسم على اثنين ونقتطع بدل القسمة على sqrt(3)، ونستخدم 3^x بدل e^x.
| Queryالاستعلام | Scoresالدرجات | Slide weightsأوزان الشريحة | Slide zz في الشريحة | Exact zz الدقيق |
|---|---|---|---|---|
| q1 = (2, 0, 3) | 3, 4, -1, 3 | .2, .6, 0, .2 | (8, 2, 6) | (10.3, 2.8, 4.6) |
| q2 = (1, 1, 2) | 2, 3, -1, 2 | .3, .3, .1, .3 | (12, 4, 3) | (10.1, 3.0, 4.5) |
| q3 = (0, 1, 2) | 2, 1, -2, 2 | .4, .2, 0, .4 | (16, 4, 2) | (15.0, 4.1, 2.1) |
| q4 = (2, 1, 1) | 1, 5, 1, 1 | .1, .7, .1, .1 | (4, 2, 7) | (3.1, 1.5, 7.7) |
Slide 44: W1 rows (1, -1, 0), (1, 1, 0), (0, 1, 1), (-1, 1, 1) with b1 = (1, 0, 1, 0); W2 rows (1, 0, 0, -1), (0, 1, 1, 0), (0, 0, 1, -1) with b2 = (0, 0, 1).
الشريحة 44: صفوف W1 هي (1, -1, 0) و(1, 1, 0) و(0, 1, 1) و(-1, 1, 1) مع b1 = (1, 0, 1, 0)، وصفوف W2 هي (1, 0, 0, -1) و(0, 1, 1, 0) و(0, 0, 1, -1) مع b2 = (0, 0, 1).
| z | W1 z + b1 | ReLU | W2 h + b2 |
|---|---|---|---|
| z1 = (11, 2, 1) | (10, 13, 4, -8) | (10, 13, 4, 0) | (10, 17, 5) |
| z2 = (6, 6, 1) | (1, 12, 8, 1) | (1, 12, 8, 1) | (0, 20, 8) |
| z3 = (7, 4, 2) | (4, 11, 7, -1) | (4, 11, 7, 0) | (4, 18, 8) |
| z4 = (7, 3, 1) | (5, 10, 5, -3) | (5, 10, 5, 0) | (5, 15, 6) |
| z5 = (5, 3, 1) | (3, 8, 5, -1) | (3, 8, 5, 0) | (3, 13, 6) |
Slide errataأخطاء الشرائح
Answer with the corrected fact, and name the slide if a question depends on it.
أجب بالمعلومة المصحّحة، واذكر رقم الشريحة إذا كان السؤال يعتمد عليها.
What the slides get wrongما تخطئ فيه الشرائح
- Slide 4الشريحة 4
- "Hidden Layer 2" labels the output row. Read it as Layer 0 hidden (4), Layer 1 hidden (3), Layer 2 output (2).عبارة "Hidden Layer 2" تسمّي صف المخرج. اقرأها هكذا: Layer 0 مخفية (4)، وLayer 1 مخفية (3)، وLayer 2 مخرج (2).
- Slides 5 to 7الشرائح 5 إلى 7
- The edge from x4 to y2 is labelled w42; by the slide's own formula it is w24. Index W as (output, input).الحافة من x4 إلى y2 مكتوب عليها w42، وبحسب صيغة الشريحة نفسها هي w24. رقّم W بالترتيب (المخرج، المدخل).
- Slide 15الشريحة 15
- "2 x2" means 2 × 2. Stride 2 is used before slide 18 defines it. The bias is silently 0."2 x2" تعني 2 × 2. الخطوة 2 مستخدمة قبل أن تعرّفها الشريحة 18. والانحياز يساوي 0 دون أن يُذكر ذلك.
- Slide 16الشريحة 16
- Reflection row 1 reads 6 5 4 5 6 4 5; the mirror rule gives 6 5 4 5 6 5 4.الصف 1 في حشو الانعكاس مكتوب 6 5 4 5 6 4 5، وقاعدة المرآة تعطي 6 5 4 5 6 5 4.
- Slide 18الشريحة 18
- Output size is written without the floor. Use floor((h_i + 2p - k)/s) + 1: 8, 3, 0, 2 gives 3, not 3.5.حجم المخرج مكتوب دون دالة الجزء الصحيح (floor). استخدم floor((h_i + 2p - k)/s) + 1: القيم 8, 3, 0, 2 تعطي 3 وليس 3.5.
- Slide 20الشريحة 20
- Depthwise W is written (c, k_h, k_w); frameworks store (c, 1, k_h, k_w). Keep four axes.W للالتفاف العمقي مكتوب (c, k_h, k_w)، والأطر البرمجية تخزّنه (c, 1, k_h, k_w). احتفظ بالمحاور الأربعة.
- Slide 21الشريحة 21
- "Max pooling performs a lot better" is an empirical heuristic (Boureau et al. 2010); modern trunks use strided convs and global average pooling. Stray capital "It".عبارة "Max pooling performs a lot better" قاعدة تجريبية (Boureau et al. 2010)، والشبكات الحديثة تستخدم الالتفاف بخطوة والتجميع المتوسط الشامل (global average pooling). وفيها حرف كبير زائد في "It".
- Slide 24الشريحة 24
- "fully connecter layer" should be "fully connected". The FC bars are class scores, probabilities only after a softmax."fully connecter layer" صوابها "fully connected". أعمدة الطبقة كاملة الاتصال درجات أصناف (class scores)، ولا تصبح احتمالات إلا بعد softmax.
- Slide 25الشريحة 25
- The ConvNetJS URL is printed with http://; the live page is https://.رابط ConvNetJS مطبوع بـ http://، والصفحة الفعلية تعمل بـ https://.
- Slide 31الشريحة 31
- Identity recovery needs gamma = sqrt(sigma² + eps), not gamma = sigma, unless eps = 0.استعادة الدالة المحايدة تحتاج gamma = sqrt(sigma² + eps) وليس gamma = sigma، إلا إذا كان eps = 0.
- Slide 38الشريحة 38
- BN is placed after the ReLU; the paper, CS231n and Goodfellow put it before the nonlinearity. Only the paper order allows fusion. Values are heavily rounded; recompute with biased variance.BN موضوع بعد ReLU، بينما الورقة الأصلية وCS231n وGoodfellow تضعه قبل الدالة غير الخطية. ترتيب الورقة وحده يسمح بالدمج. والقيم مقرّبة كثيرًا، فأعد حسابها بالتباين المتحيز.
- Slide 43الشريحة 43
- q2 is drawn as (1, 1, 1) but equals (1, 1, 2), so column 2 scores are 2, 3, -1, 2 and z2 = (12, 4, 3), not (8, 4, 4). The drawing uses column vectors, K^T Q and Z = V A.q2 مرسوم (1, 1, 1) لكنه يساوي (1, 1, 2)، لذلك درجات العمود 2 هي 2, 3, -1, 2 وz2 = (12, 4, 3) وليس (8, 4, 4). الرسم يستخدم متجهات أعمدة، وK^T Q وZ = V A.
- Slide 44الشريحة 44
- Hidden row 4 shows -9 and -4; the arithmetic gives -8 and -3. ReLU zeroes both, so the outputs stand. The attention matrix columns sum to 2, not a softmax.الصف المخفي 4 يُظهر -9 و-4، والحساب يعطي -8 و-3. ReLU تجعلهما صفرًا، فتبقى المخرجات صحيحة. وأعمدة مصفوفة الانتباه مجموعها 2، فهي ليست softmax.
- Reference deck: MIT 6.5940 lecture 2 (Song Han), which slides 2 to 20 reproduce, including the Layer 0 and w42 labels.العرض المرجعي: محاضرة MIT 6.5940 رقم 2 (Song Han)، والشرائح من 2 إلى 20 منسوخة منها، بما في ذلك تسميتا Layer 0 وw42.
- By-hand worksheets (slides 38, 43, 44) are Tom Yeh's and round heavily; recompute before quoting.أوراق الحساب اليدوي (الشرائح 38 و43 و44) من إعداد Tom Yeh وتقرّب كثيرًا، فأعد الحساب قبل أن تستشهد بها.