Constructing neural network models from brain data reveals representational transformations linked to adaptive behavior