iTranslated by AI
Understanding GPT: Generative Pre-Training for Language Understanding
This is an article for understanding GPT.
GPT is a model based on the Transformer architecture. You can find an explanatory article on the Transformer here:
I will summarize it based on the original paper "Improving Language Understanding by Generative Pre-Training".
Key Highlights
- It can perform various tasks with almost no changes to the model structure. Furthermore, it achieved State-of-the-Art (SOTA) results in 9 out of 12 tasks.
GPT Structure
Transformer Decoder (T-D)
GPT is a model that uses the Transformer Decoder (T-D) proposed in [2], and it has the following structure (shown on the left side of the figure below).

Quoted from [1] Figure 1
Similar to the initial Transformer, encoder-decoder networks were the mainstream for language models at the time. For example, in a translation task from English to German, the English word sequence (input) is fed into the encoder, and the past German word sequence (past output) is fed into the decoder to perform next-token prediction.
Specific Example
For instance, consider a task of translating the English sentence "Hello world" into the German sentence "Hallo Welt."
-
Encoder:
- First, the Encoder receives the entire English sentence "Hello world" as input.
- The Encoder processes this and generates information representing the meaning of the entire sentence (often called a context vector).
-
Decoder:
- The Decoder receives the context vector generated by the Encoder.
-
Generating the 1st word: The Decoder takes the context vector and a special token indicating the start of translation (e.g.,
<start>) as input to predict and generate the first German word "Hallo." - Generating the 2nd word: Next, the Decoder takes the context vector and the previously generated German word "Hallo" as input to predict and generate the next German word "Welt."
-
Finishing the translation: Similarly, using the context vector and the German word sequence generated so far "Hallo Welt" as input, it generates a special token indicating the end of the sentence (e.g.,
<end>), completing the translation.
In other words, "feeding the past German word sequence (past output) into the decoder" means that the Decoder uses the German word sequence it has generated so far to predict the next word. It follows a flow of generating the next word while referring to the previous translation results (past outputs) at each step.
In Decoder-only models like GPT, there is no such division of roles between an Encoder and a Decoder; instead, the input and output are treated as a single sequence for training.
The Transformer Decoder can halve the parameters but only accepts inputs from the decoder side. Therefore, it is trained by creating a sequence that combines the input sequence and the past output sequence. In other words, when there is a sequence conversion mapping like
Specific Example
Taking an English-to-German translation task as an example:
-
m = (m^1, ..., m^n)is the input English word sequence (e.g.,Hello,world) -
y = (y^1, ..., y^η)is the output German word sequence (e.g.,Hallo,Welt) -
δis a delimiter token (e.g.,<DELIMITER>)
When performing a translation task (or a similar sequence conversion task) with a Decoder-only model like GPT, the training data is prepared as follows.
Specific Example:
For training data to translate English "Hello world" into German "Hallo Welt":
-
Input sequence
m:(Hello, world) -
Output sequence
y:(Hallo, Welt) -
Delimiter
δ:<DELIMITER> -
Combined sequence
u:(Hello, world, <DELIMITER>, Hallo, Welt)
Learning Process:
The model receives this combined sequence u as a single input. Then, it learns to predict the next word.
- Seeing
Hello, it predictsworld - Seeing
Hello, world, it predicts<DELIMITER> - Seeing
Hello, world, <DELIMITER>, it predictsHallo - Seeing
Hello, world, <DELIMITER>, Hallo, it predictsWelt - ... (Continues until it predicts a token like
<end>indicating the end of the sentence)
Due to the Masked Self-Attention mechanism of the Transformer Decoder, when predicting each word, it can only refer to the words before it. This allows the model to learn the next German word to output using the input (English) and the portion already output (German).
Inference (Actually performing translation):
- Input
(Hello, world, <DELIMITER>)to the model. - The model predicts/outputs
Halloas the next word. - Next, input
(Hello, world, <DELIMITER>, Hallo)to the model. - The model predicts/outputs
Weltas the next word. - Repeat this until a token indicating the end of the sentence is output, then finish the translation.
In this way, instead of explicitly separating input and output like an Encoder-Decoder model, the method described here treats them as one long sequence and realizes sequence conversion tasks within the framework of next-word prediction.
Unsupervised Pre-training
When a set of tokens is given as
Here,
GPT utilizes the Transformer Decoder structure mentioned earlier* and is defined as follows:
Where
*Note that the transformer block uses multi-headed self-attention.
Supervised Fine-Tuning
After training to maximize Equation (1), we perform supervised learning on the target task.
We prepare a target task dataset
In what is called fine-tuning in GPT, only the parameters of the final layer of the pre-trained model are updated. That is, the input token sequence is passed through the pre-trained model to obtain the final transformer block output
auxiliary objective
The authors state that performing fine-tuning including an auxiliary objective improves generalization performance and convergence. Specifically, they introduce a new objective function:
where
Task-Specific Input Transformations
For classification tasks, we can simply perform the fine-tuning as described above. However, for tasks like answering questions based on text or evaluating similarity between sentences, we need to adapt the input. This is because the GPT model only supports learning with a single sequence, while sentence similarity tasks require two sequences of input and question-answering tasks require three sequences (text, question, and answers), making them impossible to learn as-is.
In [1], examples for Textual Entailment, Similarity, and Question Answering and Commonsense Reasoning are introduced.

Re-posted: Quoted from [1] Figure 1
There is a schematic diagram of the learning method for each task on the right side of the figure above, so checking it as needed will make the following explanation easier to understand.
Textual Entailment
This is the task of determining whether a premise token
Similarity
This evaluates the similarity between two sentences. Inserting a delimiter token between the sentences is the same as in Textual Entailment. However, since there is no inherent order between the two sentences, two input sequences with different orders are prepared and passed independently to the model to obtain the hidden states. The element-wise sum of the two obtained hidden states is taken and finally passed to a linear layer.
Question Answering and Commonsense Reasoning
This is a task to predict the answer
GPT Performance
Finally, let's look at the performance of GPT on various tasks.
Natural Language Inference Task Performance

Quoted from [1] Table 2
A performance comparison with the SOTA models of the time was conducted on six natural language inference tasks. The fine-tuned GPT model achieved SOTA in five out of the six tasks.
Question Answering and Commonsense Reasoning Performance
This was the task of obtaining an answer to a question. It achieved SOTA in all tasks.

Quoted from [1] Table 3
Semantic Similarity and Classification Performance
It achieved SOTA in four out of six tasks.

Quoted from [1] Table 4
Summary
- GPT is a model that modifies the Decoder side of the Transformer.
- It achieved SOTA on various tasks with almost no changes to the model structure or objective function.
While its power is almost hard to believe, its effectiveness has been sufficiently demonstrated by its successor models, collectively known as GPT-n, which are capable of generating text of nearly the same quality as humans.
References
- Radford, A., Narasimhan, K., Salimans, T. & Sutskever, I. (2018). Improving Language Understanding by Generative Pre-Training.
- Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L. & Polosukhin, I. (2017). Attention Is All You Need. arXiv. https://doi.org/10.48550/arxiv.1706.03762
Discussion