Entanglement calculations in quantum field theories are extremely challenging and typically rely on the replica trick, where the problem is rephrased in a study of defects. We demonstrate that the use of deep generative models drastically outperforms standard Monte Carlo algorithms. Remarkably, such a machine-learning method enables high-precision estimates of Rényi entropies in three dimensions for very large lattices. Moreover, we propose a new paradigm for studying lattice defects with flow-based sampling.