Disentangling neural network representations for improved generalization