Learning useful representations for shifting tasks and distributions