A classification head is the task-specific part of a neural network that turns learned representations into class predictions. Attached to a general-purpose backbone, it specializes the model for a classification task, much like choosing a screwdriver head for a particular job. section 15.4.2
A practical classification head commonly performs these steps:
- Condenses a sequence representation into one vector per sample, using the first token representation rather than mean- or max-pooling. section 15.4.4
- Transforms that vector with a Dense projection, a ReLU nonlinearity, and dropout before producing the prediction. section 15.4.4
- Uses a final one-unit sigmoid output with binary crossentropy and accuracy for binary classification. section 15.4.4
Listing 15.22 Extending the base RoBERTa model for classification
inputs <- backbone$input outputs <- inputs |> backbone() |> op_subset(, 1, ) |> #1 layer_dropout(0.1) |> layer_dense(768, activation = "relu") |> layer_dropout(0.1) |> layer_dense(1, activation = "sigmoid") classifier <- keras_model(inputs, outputs)
The Keras model definition shows a RoBERTa backbone extended with contextual representation selection, dropout, Dense layers, and a sigmoid classification output. section 15.4.4
IMDb review classification
A pretrained RoBERTa backbone can be extended with this head and fine-tuned on IMDb reviews. The resulting model reached 93% accuracy after one epoch, improving on a simpler classifier’s 90% ceiling. section 15.4.4

