Neural Mechanisms For Flexible Behaviour In Humans And Artificial Neural Networks