Learning encodings by maximizing state distinguishability: Variational quantum error correction