A general Bayesian model for hierarchical inference