Compression, generation, and inference via supervised learning