Implement the generator part of a simple GAN (Generative Adversarial Network).
The generator maps noise z to a fake sample through two layers:
The tanh output ensures generated values are in [-1, 1].
Also compute the generator loss. Given a discriminator that outputs a score for the fake sample, the generator loss (non-saturating) is:
$$L_G = -\log(\sigma(D(\text{fake})))$$
where $\sigma$ is sigmoid and $D(\text{fake})$ is given as input.
Input:
z: noise vector shape (batch, noise_dim) W1: shape (noise_dim, hidden_dim), b1: shape (hidden_dim,) W2: shape (hidden_dim, output_dim), b2: shape (output_dim,) disc_score: discriminator output for fake, shape (batch, 1)
Output: A dict with “fake” (shape (batch, output_dim)) and “loss” (scalar).