liveBook · Manning

Classification head

As explained in Deep Learning with R, Third Edition

A classification layer is a neural-network layer that produces outputs representing predicted class assignments or probabilities.

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

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains contextual pooling, Dense projection, dropout, sigmoid output, loss selection, and training, while deferring broader architecture theory.
Examples
Uses a RoBERTa model, first-token contextual representation, and IMDb review classification as concrete examples.
What you can do after
Build it from scratch by attaching and training a classification head on a pretrained Transformer backbone.
How it connects
Connects backbones with Transformers, attention, fine-tuning, Dense layers, sigmoid activation, and binary crossentropy.

Also explained in

Compare how 2 books explain classification head →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.