Skip to main content

Chapter 11.2 - Generating Text Batches


Overview

every epoch can contain many batches. every batch can contain many training sets. simple analogy is that 1 batch= the weights changed once 1 epoch= the entire dataset has been read through once

Suppose we have:

  • 1000 Training Sets
  • Batch Size = 50
  1. Number of batches:

    • 1000 ÷ 50 = 20 batches
  2. Each batch processes 50 training sets and performs 1 weight update.

  3. Therefore:

    • 20 batches = 20 weight updates
  4. After all 20 batches are processed, the model has seen all 1000 training sets once. This is called 1 Epoch.

  5. If we train for 10 epochs:

    • 20 batches/epoch × 10 epochs = 200 weight updates
Epoch 1

Batch 1 (Examples 1–50)
↓ Update weights

Batch 2 (Examples 51–100)
↓ Update weights...

Batch 20 (Examples 951–1000) ↓
Update weights✅

Entire dataset has now been seen once
= 1 Epoch Completed (20 times weight changed)

sentance = "hi my name is harshu who really loves my family"

Batch 1

Context SeenOutputProbability of OutputTargetProbability of TargetFull Probability Matrix Strip [hi, my, name, is, harshu, who, really, loves, family]
hihi0.24my0.13[0.24, 0.13, 0.11, 0.09, 0.12, 0.10, 0.08, 0.07, 0.06]
hi myreally0.18name0.10[0.09, 0.12, 0.10, 0.11, 0.13, 0.14, 0.18, 0.07, 0.06]
hi my namemy0.21is0.12[0.08, 0.21, 0.09, 0.12, 0.13, 0.11, 0.10, 0.09, 0.07]
hi my name isharshu0.29harshu0.29[0.05, 0.06, 0.07, 0.09, 0.29, 0.16, 0.12, 0.09, 0.07]
mymy0.26name0.12[0.08, 0.26, 0.12, 0.10, 0.08, 0.14, 0.09, 0.07, 0.06]
my namereally0.20is0.09[0.07, 0.11, 0.15, 0.09, 0.14, 0.13, 0.20, 0.06, 0.05]
my name iswho0.22harshu0.11[0.06, 0.09, 0.10, 0.13, 0.11, 0.22, 0.12, 0.10, 0.07]
my name is harshuwho0.31who0.31[0.04, 0.06, 0.08, 0.07, 0.09, 0.31, 0.14, 0.13, 0.08]

Batch 2

Context SeenOutputProbability of OutputTargetProbability of TargetFull Probability Matrix Strip [hi, my, name, is, harshu, who, really, loves, family]
namename0.24is0.13[0.06, 0.12, 0.24, 0.13, 0.09, 0.14, 0.10, 0.07, 0.05]
name iswho0.21harshu0.12[0.05, 0.08, 0.10, 0.18, 0.12, 0.21, 0.11, 0.09, 0.06]
name is harshureally0.20who0.14[0.05, 0.07, 0.08, 0.09, 0.16, 0.14, 0.20, 0.13, 0.08]
name is harshu whoreally0.30really0.30[0.04, 0.05, 0.06, 0.06, 0.09, 0.12, 0.30, 0.18, 0.10]
isis0.25harshu0.13[0.05, 0.09, 0.08, 0.25, 0.13, 0.14, 0.10, 0.09, 0.07]
is harshuwho0.29who0.29[0.04, 0.06, 0.06, 0.08, 0.11, 0.29, 0.15, 0.13, 0.08]
is harshu wholoves0.28really0.16[0.04, 0.06, 0.06, 0.07, 0.08, 0.17, 0.16, 0.28, 0.08]
is harshu who reallyloves0.35loves0.35[0.03, 0.04, 0.04, 0.05, 0.05, 0.09, 0.15, 0.35, 0.20]

Batch 3

Context SeenOutputProbability of OutputTargetProbability of TargetFull Probability Matrix Strip [hi, my, name, is, harshu, who, really, loves, family]
harshuharshu0.24who0.12[0.05, 0.09, 0.08, 0.08, 0.24, 0.12, 0.13, 0.15, 0.06]
harshu whoreally0.28really0.28[0.04, 0.06, 0.05, 0.05, 0.09, 0.16, 0.28, 0.18, 0.09]
harshu who reallyloves0.34loves0.34[0.03, 0.04, 0.04, 0.05, 0.05, 0.10, 0.16, 0.34, 0.19]
harshu who really lovesfamily0.33my0.18[0.03, 0.18, 0.04, 0.05, 0.05, 0.06, 0.08, 0.18, 0.33]
whowho0.23really0.16[0.04, 0.09, 0.08, 0.08, 0.09, 0.23, 0.16, 0.14, 0.09]
who reallyloves0.31loves0.31[0.03, 0.05, 0.05, 0.05, 0.06, 0.12, 0.18, 0.31, 0.15]
who really lovesmy0.39my0.39[0.03, 0.39, 0.04, 0.04, 0.04, 0.06, 0.09, 0.18, 0.13]
who really loves mymy0.34family0.17[0.03, 0.34, 0.03, 0.03, 0.03, 0.06, 0.09, 0.22, 0.17]

Sentence = "hi my name is harshu who really loves my family"

  • Total words (tokens) = 10
  • Context Length (TT) = 4
  • Batch Size (BB) = 2
  • Training Sets (NN) = 24
  • Batch Size Number of context-length input sequences passed to the model in one batch.
    • eg batch 1 has 2 (hi my name is & my name is harshu)
  • context length is length of 1 input eg (my name is harshu) =4 tokens =4
  • no. of training sets that can be created =
Total Training Sets=(Total TokensContext Length)×Context Length\text{Total Training Sets} = (\text{Total Tokens} - \text{Context Length}) \times \text{Context Length} Number of Batches=Number of Training SetsContext Length×Batch Size=244×2=3\text{Number of Batches} = \frac{\text{Number of Training Sets}} {\text{Context Length} \times \text{Batch Size}} = \frac{24}{4 \times 2} = 3

If we train for EE epochs:

Total Batch Iterations=Number of Batches×Epochs\text{Total Batch Iterations} = \text{Number of Batches} \times \text{Epochs}

Example (Epochs=5Epochs=5):

Total Batch Iterations=3×5=15\text{Total Batch Iterations} = 3 \times 5 = 15