Fine-Tuning, and When Not ToLesson 60 of 84

Module 7 · Fine-tuning beyond a chat model

Fine-tuning a classifier properly

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 3 of 9 in this chapter

This chapter’s goalAdapt an embedding model, a reranker, a text classifier, a speech model, a vision-language model or an image generator, and name in each case what differs from fine-tuning a text LM and which cheaper technique should be tried first.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

The setup

Module one argued that a fixed set of labels wants an encoder rather than a generative model. This is how that is done.

Python
from transformers import AutoModelForSequenceClassification, AutoTokenizer

MODEL = "answerdotai/ModernBERT-base"     # 149M; or microsoft/deberta-v3-base
tok = AutoTokenizer.from_pretrained(MODEL)
model = AutoModelForSequenceClassification.from_pretrained(
    MODEL, num_labels=6, id2label=ID2LABEL, label2id=LABEL2ID)

Pass id2label and label2id. They are saved in the config, which means the model that comes back off disk in six months says what its outputs mean. Without them you have a tensor of six numbers and a note in somebody’s head.

Full fine-tuning at this size costs about 6 GB of GPU memory at a learning rate of 2e-5 for 3 to 5 epochs. No adapters, no quantisation; the model is small enough that all the machinery from earlier modules is unnecessary.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Running Models Yourself exam.

Stuck on something?Ask Rafael, your AI tutor

How to cite: Addaly (2026) ‘Fine-tuning a classifier properly’, in Fine-Tuning, and When Not To. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/fine-tuning/fine-tuning-a-classifier (Accessed: 29 November 2026).