An encoder turns an input into an internal representation that another component can use. In a transformer encoder–decoder pipeline, text is tokenized, converted to embedding vectors, and processed into hidden states for the decoder. Not every language model uses this arrangement: GPT-3 is described as decoder-only. section 2.8 section 2.3
The input and the purpose of its representation depend on the application:
- In Stable Diffusion, a text encoder converts an image prompt into a vector representation used within the image-generation system. section 4.1.4
- In retrieval-augmented generation (RAG), a query encoder converts a question into a vector so a retriever can find relevant, pre-encoded documents. section 7.3
- Encoders also process images: a variational autoencoder maps an image into a latent representation, while a vision transformer learns relationships among image patches. section 4.1.1 section 4.1.3
Finding context for an enterprise question
A RAG system encodes an employee’s question as a query vector. Its retriever compares that vector with a precompiled index of document vectors, selects relevant documents, and passes their information to the LLM to generate an answer. section 7.3
When choosing an architecture, distinguish the encoder’s job from the system’s final output: encoding prepares a representation; a decoder, retriever, or image-generation component uses it. Resource needs also matter—transformers can require substantial computation, and vision transformers face training and inference costs. section 2.3 section 4.1.3
Figure 2.3 Conceptual architecture of an LLM
The architecture diagram shows where token embeddings enter the encoder and how its hidden states feed the decoder. section 2.8




















