Robust & Flexible Representations Under Distribution Shift