Predicting citywide flows is an essential task for city risk assessment, traffic management, and urban planning, which profoundly impacts people’s lives and property. Recently, some deep learning models have been proposed for flow prediction. However, these existing models mainly focus on capturing spatio-temporal (ST) correlations between regions but overlook to model the latent function of each region that can impact the ST correlations greatly. Thus, it is necessary to have a framework to assist these deep models in tackling the region function issue. However, it is very challenging because of two problems: 1) How to make deep models predict flows taking into consideration the latent region function; 2) how to make the framework generalize to a wide range of deep models while preserving the model complexity. To tackle these challenges, we propose a novel deep learning framework that employs matrix factorization for spatio-temporal neural networks (MF-STN), capable of enhancing the state-of-the-art deep ST models. MF-STN consists of two components: 1) a ST feature learner, which is used to obtain features of ST correlations of all regions by the corresponding sub-network of the existing deep networks; and 2) a region-specific predictor, which leverages the learned ST features to make region-specific predictions. In particular, we use the matrix factorization technique on the neural networks, namely, decomposing the region-specific parameters of the predictor into learnable matrices, i.e., region embedding matrices and parameter embedding matrices, such that the latent region function along with the correlations among regions can be modeled. Extensive experiments were conducted based on two real-world datasets, demonstrating that MF-STN can significantly improve the performance of several representative neural networks while preserving the model complexity. Moreover, MF-STN has been used as a bedrock in a real-world urban flow prediction application.