Training feeds data through a model and adjusts its parameters so it can learn patterns in the data. For a clothing-image GAN, training alternates between updating the discriminator on real samples, updating it on generated samples, and updating the generator. section 4.1.3
A practical check is to inspect generated outputs over time. In the clothing example, the untrained generator produces noise-like images; after training, its outputs begin to resemble clothing. section 4.1.3
Listing 4.3 Training GANs for clothing item generation
for i in range(50):
gloss=0
dloss=0
for n, (real_samples,_) in enumerate(train_loader):
loss_D=train_D_on_real(real_samples) #1
dloss+=loss_D
loss_D=train_D_on_fake() #2
dloss+=loss_D
loss_G=train_G() #3
gloss+=loss_G
gloss=gloss/n
dloss=dloss/n
if i % 10 == 9:
print(f"at epoch {i+1}, dloss: {dloss}, gloss {gloss}")
see_output() #4
See the batch loop: it alternates discriminator and generator updates, then visualizes generated images every ten epochs. section 4.1.3
Text-generation training also depends on preparing suitable input data. The GPT example tokenizes three novels, maps tokens to integers, and divides the resulting sequence into fixed-length training sequences. section 12.1.2























