Autoregressive models are among the best performing neural densityestimators. We describe an approach for increasing the flexibility of anautoregressive model, based on modelling the random numbers that the model usesinternally when generating data. By constructing a stack of autoregressivemodels, each modelling the random numbers of the next model in the stack, weobtain a type of normalizing flow suitable for density estimation, which wecall Masked Autoregressive Flow. This type of flow is closely related toInverse Autoregressive Flow and is a generalization of Real NVP. MaskedAutoregressive Flow achieves state-of-the-art performance in a range ofgeneral-purpose density estimation tasks.