Encoder

An encoder is the part of a neural network that reads an input, such as text, audio or an image, and converts it into internal numerical representations that the rest of a system can use.

An encoder's job is to understand rather than to produce. It takes raw input and turns it into vectors that capture what matters about it. Its partner, the decoder, works the other way, turning internal representations into an output such as a translated sentence or a reconstructed image.

The transformer architecture introduced in the 2017 paper Attention Is All You Need was built from an encoder and a decoder. The encoder was a stack of six identical layers, each combining self-attention with a simple feed-forward network. Because the encoder sees the whole input at once, every token can attend to every other token, before and after it, and the encoder outputs one context-aware vector per token. The decoder then consults those vectors through a separate attention step while it writes the output.

Encoders also work on their own. Encoder-only models such as BERT keep just this half of the transformer and are used for classification, search and producing embeddings. In multimodal systems an image or vision encoder converts pictures into vectors. OpenAI's CLIP, released in January 2021, trained an image encoder and a text encoder together so that matching pictures and captions end up close together, and the original Stable Diffusion used CLIP's text encoder to turn a written prompt into the embeddings that guide image generation.

The word has a slightly different flavour in an autoencoder. There, as Google's machine learning glossary describes it, the encoder squeezes an input into a smaller intermediate form and the decoder tries to rebuild the original from it, so the model learns what information is worth keeping.

In AI news, encoder in this sense has nothing to do with the video encoders used to compress footage for streaming. When a story says a model uses a new vision encoder or text encoder, it means the component that turns raw input into the representation the rest of the model reasons over, which often sets limits on what detail the model can see.

Common questions

What is the difference between an encoder and a decoder?

An encoder reads an input and turns it into internal representations. A decoder takes representations and produces an output, usually one piece at a time. In the original transformer the encoder read the source sentence and the decoder wrote the translation while consulting the encoder's output.

Do chatbots like ChatGPT have an encoder?

Not in the original sense. GPT models use only the decoder part of the transformer, treating the prompt and the reply as one sequence and predicting the next token. Multimodal chatbots do add encoders for other inputs, such as an image encoder that converts pictures into vectors the language model can work with.

What does a text encoder do in an image generator?

It converts the written prompt into embeddings that steer the image generation process. The original Stable Diffusion, for example, used the text encoder from OpenAI's CLIP for this. The quality of the text encoder affects how well the generator follows detailed or unusual prompts.

Why are encoders used for search and classification?

Because an encoder reads the whole input at once and can summarise it as vectors in a single pass, without generating anything. That makes it cheap and fast to label text or compare documents, which is why many embedding and classification models are encoder-based.

Finding more

Search for "transformer encoder", "encoder vs decoder" or "vision encoder" to see how the component is used in different models. Reliable sources include the original transformer paper on arXiv, machine learning glossaries such as Google's, and model papers or technical reports that describe their architecture. Diagrams in blog posts are often simplified, so check details such as layer counts against the original paper.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.