Encoder transforms input data into a compact representation, while Decoder reconstructs output from that representation. The encoder captures essential features, and the decoder ensures the output is coherent and relevant.
In models like Transformers, the encoder processes the entire input simultaneously, while the decoder uses masked attention to prevent future information leakage during generation.