Hierarchical Bayesian inference of the initial mass function in composite stellar populations