Lanuage Modeling Head

Here, the word head refers to the additional neural circuitry that is added on top of the basic transformer architecture when we apply pretrained transformer models to various tasks. The language model head is the circuitry we need to do language modeling. The task of the language modeling head is to take the output of the final transformer layer from the last token NN and use it to predict the upcoming word at position N+1N + 1.

The language modeling head consists of a linear layer and a softmax layer.

  1. Unembedding Layer The unembedding layer is a linear layer which projects the output hNLh_N^L (the output token embedding at position NN from the final transformer block LL) to the logit vector that will have a single score for each of the V|V| possible words in the vocabulary VV. The logit vector, u\textbf{u}, has a dimensionality of 1×V1 \times |V|.

    u=hNLWU\begin{align} \textbf{u} = h^L_N W_U \end{align}
  2. Softmax Layer The logits u\textbf{u} from the unembedding layer are converted into probabilities y\textbf{y} over the vocabulary by a softmax layer.

    y=softmax(u)\begin{align} \textbf{y} = \text{softmax}(\textbf{u}) \end{align}

To generate text, a word is decoded from the probabilities y\textbf{y} obtained from the Softmax layer.