Skip to content
tezvyn:
Menu

Explain GAN architecture, generator and discriminator roles, and objective function

Source: interviewEasyHow cards are made

Tests adversarial training as a minimax game. Strong answers: generator maps noise z to fakes; discriminator classifies real versus fake; both optimize V(D,G)=E[log D(x)]+E[log(1-D(G(z)))].

What's really being asked

This question probes whether you understand generative modeling through adversarial dynamics rather than memorizing a diagram. Interviewers want to see that you treat the generator and discriminator as coupled players in a game, not as isolated networks with private loss functions. At the senior level, clarity on why alternating optimization is necessary and how gradients flow through both networks separates candidates who have trained GANs from those who have only read about them.

The full answer

A strong response hits four points in order. First, the generator G is a neural network that takes a latent vector z sampled from a simple prior like a standard Gaussian and maps it through upsampling or transposed convolution layers to produce synthetic data G of z that aims to match the true data distribution. Second, the discriminator D is a binary classifier typically built from convolutional or dense layers that outputs a scalar probability D of x representing the chance that input x came from the real dataset rather than from G. Third, training proceeds alternately rather than simultaneously in most implementations: fix G and train D for k steps to better distinguish real from fake, then fix D and train G for one step to maximize the probability that D misclassifies G of z as real. Fourth, the joint objective is the minimax value function V of D and G equals the expectation over real data x of log D of x plus the expectation over noise z of log of one minus D of G of z, where D tries to maximize V and G tries to minimize it.

The mistakes people make

Red flags include describing the generator and discriminator as optimizing two independent losses without referencing the shared value function, claiming both networks update at exactly the same time in a single forward or backward pass, or stating that G minimizes binary cross entropy directly instead of maximizing log D of G of z. Another frequent mistake is omitting the latent space entirely or suggesting that G learns a deterministic copy of the training set rather than the underlying distribution.

What usually comes next

Expect the interviewer to ask why the original GAN paper uses log of one minus D of G of z for the generator rather than the more practical heuristic of maximizing log D of G of z, or how mode collapse manifests when G discovers a single sample that always fools D. They may also ask about spectral normalization, Wasserstein variants, or whether the discriminator can be reused as a feature extractor.

A concrete example

When training a GAN on the MNIST dataset, the generator might accept a hundred-dimensional noise vector and output a twenty-eight by twenty-eight grayscale image. The discriminator receives either a real MNIST digit or the generator output and predicts a single probability. In practice, the discriminator is updated for five minibatches while the generator is frozen, then the generator is updated for one minibatch while the discriminator is frozen, with the generator target set to one so that binary cross entropy drives D of G of z toward one.

Interview question

In the standard GAN minimax objective, what is the generator G's optimization goal?

  • a.Minimize the expectation of log(1 - D(G(z))) so the discriminator misclassifies fakes as real.Correct
  • b.Maximize the expectation of log D(x) over real training examples to copy the dataset.
  • c.Maximize the shared value function V(D,G) so that D correctly classifies real versus fake samples.
  • d.Minimize binary cross-entropy against real data labels independently of the discriminator.
Why?

The generator minimizes the value function V, which is equivalent to minimizing the expectation of log(1 - D(G(z))) so that D assigns high probability to fake samples. Distractor A is wrong because maximizing V is the discriminator's objective, not the generator's.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles