How can a two-layer MLP with two ReLU hidden units and a linear output unit compute the XOR function on (x1,x2)∈{0,1}2, and what values do its hidden units and output take on all four inputs?

Deep learning, Multilayer perceptrons
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you can construct an explicit non-linear feature mapping with ReLU units to separate a non-linearly separable problem.

Key idea

Set h1=ReLU⁡(x1+x2), h2=ReLU⁡(x1+x2−1) and y^=h1−2h2. The hidden units map (0,0), (0,1)/(1,0) and (1,1) to (0,0), (1,0) and (2,1), which are linearly separable.

Steps

  1. Define the hidden layer h=ReLU⁡(Wx+b) with W=[1111] and b=[0−1], and output y^=w⊤h with w=[1−2].
  2. For (x1,x2)=(0,0): h1=ReLU⁡(0)=0 and h2=ReLU⁡(−1)=0, giving y^=0.
  3. For (0,1) and (1,0): h1=ReLU⁡(1)=1 and h2=ReLU⁡(0)=0, giving y^=1−2(0)=1.
  4. For (1,1): h1=ReLU⁡(2)=2 and h2=ReLU⁡(1)=1, giving y^=2−2(1)=0.

Common mistakes

How long your answer should be

4–5 lines with the weights and the four-row evaluation table.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: In a U-Net encoder–decoder for image segmentation, why are encoder feature maps concatenated directly to the corresponding decoder layers instead of relying on the bottleneck alone?
Next in Deep learning: In a small computation graph, input x=2 feeds two branches that share the same weight w=3: a=wx and b=(w−1)2, and the loss is L=12(ab−20)2. How do you compute ∂L∂w by backpropagation, and what happens if an implementation overwrites instead of accumulating branch gradients?