Learning efficient task-dependent representations with synaptic plasticity