A powerful way of encoding and decoding text is to use sequence models.
f µ (x) and f σ (x) would map from a sequence of tokens to a pair of vectors, µ and σ, and f d (z) would similarly decode from z to a sequence of tokens, using recurrent, convolutional, or attention-based networks.