Encoder Decoder Neural Network Simplified, Explained & State Of The Art

by | Jan 6, 2023 | Artificial Intelligence, Natural Language Processing

Encoder, decoder and encoder-decoder transformers are a type of neural network currently at the bleeding edge in NLP. This article explains the difference between these architectures and what they are used for.

What is a transformer?

A transformer is a kind of neural network architecture used in natural language processing (NLP) to process sequential data. It was first discussed in the 2017 paper “Attention is All You Need” by Vaswani et al. It has since been widely applied to language modelling, summarisation, and machine translation tasks.

Instead of using a fixed window of adjacent elements as in conventional RNNs or CNNs, the transformer architecture is based on self-attention, which enables the model to compare any two input elements with one another directly. This makes it easier to train and run the transformer than models based on RNNs or CNNs, and it also makes it better to find long-range dependencies in the input data.

The transformer architecture has generally been very effective in NLP and has resulted in appreciable performance improvements on various tasks. It has also been used in other fields, like computer vision, and has many potential applications.

Encoder Decoder Neural Network have lead to improved performance

Transformers have led to increased performance in various NLP tasks.

What is an encoder in a neural network?

Known as a latent representation or embedding, an encoder is a part of a neural network that processes the input data and transforms it into a compact model. This latent representation, which usually has fewer dimensions than the original data, tries to capture the original data’s most important parts or traits more concisely.

A sequence of words or tokens in a sentence or document is processed by an encoder in a natural language processing (NLP) context and transformed into a continuous, fixed-length vector representation. This vector representation can then be fed into a decoder or a classifier, among other model parts.

Encoders are frequently employed in tasks like machine translation. For example, the encoder analyses the input sentence in the source language. It produces a latent representation, which is then sent to a decoder, which does the translation in the target language. Additionally, they are employed in language modelling, where the encoder analyses a run of words and forecasts the following term.

What is a decoder in a neural network?

A decoder is a part of a neural network that takes an embedding-like compact representation of the input data and changes it into a more helpful format for the task at hand. For example, in natural language processing (NLP), a decoder is often used to make text from an input embedding that shows the context or meaning of the text.

For instance, in machine translation, the decoder uses the latent representation created by the encoder as input to produce the translation in the target language. In language modelling, the decoder predicts the following word in the sequence using the embedding produced by the encoder as input.

Recurrent neural networks (RNNs) or transformers are frequently used in the implementation of decoders, allowing them to process sequential input data and produce output sequences of varying lengths. They can also be used in conjunction with attention mechanisms, which let the decoder generate the output while selectively focusing on various elements of the input embedding.

What is an encoder-decoder architecture in a neural network?

A typical neural network architecture for tasks involving changing a sequence of data from one form to another is an encoder-decoder. It is made up of an encoder and a decoder.

The encoder processes the input sequence into an embedding—a condensed, fixed-length representation. The embedding, which usually has fewer dimensions than the original data, tries to capture better the most important parts or characteristics of the original data.

The output sequence, which should be a modified version of the input sequence, is then produced by the decoder after processing the embedding.

For example, in machine translation, an input sequence is a sentence in the source language, an embedding is a hidden representation of the sentence’s meaning, and an output sequence is the translation of the sentence into the target language.

Generally speaking, the encoder-decoder architecture is famous for tasks involving sequential data and has proven particularly effective in natural language processing (NLP) applications. However, it has also been used in other fields, like computer vision, and has many potential applications.

What is the difference between encoder, decoder and encoder-decoder in a neural network?

The input data is processed by an encoder transformer that embeds it in a condensed, fixed-length representation. The embedding, which usually has fewer dimensions than the original data, tries to capture better the most important parts or characteristics of the original data.

An embedding is processed by a decoder transformer, which then transforms it back into a format better suited for the task. In machine translation, for example, the latent representation made by the encoder is used by the decoder as input to do the translation in the target language.

An encoder-decoder transformer is frequently used when converting a sequence of data from one form to another, as is the case when performing machine translation, summarisation, or language modelling. The encoder processes the input sequence, which also creates an embedding. This embedding is then given to the decoder, which makes the output sequence.

In general, you would use an encoder when you wanted to compress the input data, a decoder when you needed to produce some output based on the input, and an encoder-decoder when you needed to change the format of a sequence of data.

Applications of encoder and decoder architecture in a neural network


  • Image classification: An encoder can analyse an image and produce a compact embedding that encapsulates its features or characteristics. A classifier can be given the embedding to determine the label or class of the picture.
  • Speech recognition: By analysing a waveform, an encoder can produce an embedding that depicts the features or traits of the speech signal. The embedding can then be given to a classifier to predict the transcription of the speech.


  • Text generation: Given an input embedding that represents the context or meaning of the text, a decoder can produce a string of words or tokens. For example, a decoder could make a document summary based on an embedding that shows what the document is about.
  • Image creation: A decoder can be used to create an image if an input embedding represents the features or characteristics of the picture. An embedding that means the pose and appearance of the person, for instance, could be used by a decoder to create a photo-realistic image of the person.


  • Text translation: A sentence in one language can be translated into a sentence in another language using an encoder-decoder (also known as machine translation). The decoder produces a translation using an embedding made by the encoder after processing the input sentence.
  • Summarisation: Given the complete text of a document, an encoder-decoder can produce a summary of the document. So that the decoder can make the summary, the encoder has to process the document and make an embedding.
  • Language modelling: By using the previous words in the sentence as input, an encoder-decoder can predict the following word in a sentence. The decoder uses the embedding to predict the next word after the encoder has processed the input sentence up to the current word.

State-of-the-art transformers

Since the original transformer model was introduced in the paper “Attention is All You Need” by Vaswani et al., there have been numerous developments in transformers (2017). Following are a few examples of contemporary transformer models created since then:

  • BERT (Devlin et al., 2018): Among other natural language processing (NLP) tasks, BERT (Bidirectional Encoder Representations from Transformers) has attained state-of-the-art performance on a variety of NLP tasks, including language understanding, natural language generation, and machine translation. It can accurately capture the context and relationships between words in a sentence because it was trained using a combination of supervised and unsupervised learning.
  • GPT-3 (Brown et al., 2020): A transformer-based model called GPT-3 (Generative Pre-training Transformer 3) has achieved cutting-edge performance on various language tasks, including translation, summarisation, question-answering, and text generation. It can write a text that sounds like a human wrote it because it was trained using both supervised and unsupervised learning.
  • T5 (Raffel et al., 2020): Using a single, unified architecture, the transformer-based model T5 (Text-To-Text Transfer Transformer) can carry out various natural language processing tasks. It can learn new tasks quickly and effectively without requiring task-specific fine-tuning. It has attained state-of-the-art performance on tasks like language translation, summarisation, and question-answering.

Overall, transformers have made a big difference in natural language processing and can be used in many situations.


Different neural network architectures, such as encoder, decoder, and encoder-decoder transformers, are frequently employed for sequential data processing tasks.

An encoder transformer is usually used to change the input data into a format that is easier to work with or takes up less space.

A decoder transformer is often used to get something out of the data you put in, like a translation, a summary, or a prediction.

An encoder-decoder transformer is frequently used when converting a sequence of data from one form to another, as is the case when performing machine translation, summarisation, or language modelling.

Overall, whether you should use an encoder, decoder, or encoder-decoder transformer will depend on the task you are trying to do and the needs of your application.

About the Author

Neri Van Otten

Neri Van Otten

Neri Van Otten is the founder of Spot Intelligence, a machine learning engineer with over 12 years of experience specialising in Natural Language Processing (NLP) and deep learning innovation. Dedicated to making your projects succeed.

Recent Articles

Factor analysis example of what is a variable and what is a factor

Factor Analysis Made Simple & How To Tutorial In Python

What is Factor Analysis? Factor analysis is a potent statistical method for comprehending complex datasets' underlying structure or patterns. Its primary objective is...

glove vector example "king" is to "queen" as "man" is to "woman"

How To Implement GloVe Embeddings In Python: 3 Tutorials & 9 Alternatives

What are GloVe Embeddings? GloVe, or Global Vectors for Word Representation, is an unsupervised learning algorithm that obtains vector word representations by analyzing...

q-learning explained witha a mouse navigating a maze and updating it's internal staate

Reinforcement Learning: Q-learning & Deep Q-Learning Made Simple

What is Q-learning in Machine Learning? In machine learning, Q-learning is a foundational reinforcement learning technique for decision-making in uncertain...

DALL-E the text description "A cat sitting on a beach chair wearing sunglasses,"

Generative Artificial Intelligence (AI) Made Simple [Complete Guide With Models & Examples]

What is Generative Artificial Intelligence (AI)? Generative artificial intelligence (GAI) is a type of AI that can create new and original content, such as text, music,...

5 key aspects of GPT prompt engineering

How To Guide To Chat-GPT, GPT-3 & GPT-4 Prompt Engineering [10 Types]

What is GPT prompt engineering? GPT prompt engineering is the process of crafting prompts to guide the behaviour of GPT language models, such as Chat-GPT, GPT-3,...

What is LLM Orchestration

How to manage Large Language Models (LLM) — Orchestration Made Simple [5 Frameworks]

What is LLM Orchestration? LLM orchestration is the process of managing and controlling large language models (LLMs) in a way that optimizes their performance and...

Content-Based Recommendation System where a user is recommended similar movies to those they have already watched

How To Build Content-Based Recommendation System Made Easy [Top 8 Algorithms & Python Tutorial]

What is a Content-Based Recommendation System? A content-based recommendation system is a sophisticated breed of algorithms designed to understand and cater to...

Nodes and edges in a knowledge graph

Knowledge Graph: How To Tutorial In Python, LLM Comparison & 23 Tools & Libraries

What is a Knowledge Graph? A Knowledge Graph is a structured representation of knowledge that incorporates entities, relationships, and attributes to create a...

The mixed signals and need to be reverse-engineer to get the original sources with ICA

Independent Component Analysis (ICA) Made Simple & How To Tutorial In Python

What is Independent Component Analysis (ICA)? Independent Component Analysis (ICA) is a powerful and versatile technique in data analysis, offering a unique perspective...


Submit a Comment

Your email address will not be published. Required fields are marked *

nlp trends

2024 NLP Expert Trend Predictions

Get a FREE PDF with expert predictions for 2024. How will natural language processing (NLP) impact businesses? What can we expect from the state-of-the-art models?

Find out this and more by subscribing* to our NLP newsletter.

You have Successfully Subscribed!