Start by clarifying the architecture (e.g., 2-2-1 with sigmoid activations) and then walk through the forward pass with explicit tensor shapes. Next, derive the backpropagation using the chain rule, implement cross-entropy loss, and finally describe mini-batch SGD training on XOR, highlighting shape consistency at each step.
Pro tip: Emphasize that you always verify tensor shapes by printing them during implementation, and mention that for XOR you need a hidden layer to capture non-linearity. This shows practical debugging skills and deep understanding.
Choose a simple feed-forward network (e.g., 2 input, 2 hidden, 1 output) with sigmoid activations. Initialize weights randomly with small values and biases to zero, noting shapes: W1 (2x2), b1 (1x2), W2 (2x1), b2 (1x1).
For a batch of inputs X (batch_size x 2), compute Z1 = X·W1 + b1 (batch_size x 2), A1 = sigmoid(Z1), Z2 = A1·W2 + b2 (batch_size x 1), A2 = sigmoid(Z2). Track shapes at each operation.
For binary classification, use binary cross-entropy: L = -1/N * sum(y*log(A2) + (1-y)*log(1-A2)). Note that for multi-class, softmax + categorical cross-entropy would be used, but XOR is binary.
Compute gradients: dZ2 = A2 - y (batch_size x 1), dW2 = A1.T·dZ2 (2x1), db2 = sum(dZ2, axis=0) (1x1). Then dA1 = dZ2·W2.T (batch_size x 2), dZ1 = dA1 * sigmoid_derivative(Z1) (batch_size x 2), dW1 = X.T·dZ1 (2x2), db1 = sum(dZ1, axis=0) (1x2).
Shuffle data, split into mini-batches (e.g., size 2 for XOR). For each epoch, iterate over batches: forward pass, compute loss, backprop, update weights: W -= learning_rate * dW. Repeat until convergence, monitoring loss.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.