All courses Machine learning

Hugging Face Transformers: Fine-Tune a Pretrained Model

Intermediate

Run, measure and fine-tune a small model that sorts customer messages, all on a CPU.

Intermediate 8 lessons 26 lab exercises Certificate Updated

You build

A text classifier that reads a short message from a bank customer about their card and names which of ten requests it is, made by fine-tuning the small pretrained DistilBERT model on real labelled customer messages from the Banking77 dataset.

You need

  • Python: functions, lists, dictionaries, loops, and running a script from a terminal
  • The basics of deep learning in PyTorch: what a tensor, a neural network, a loss and a training loop are, and having trained and measured a small network yourself. The course Deep Learning with PyTorch teaches all of it and is one way to get there.

To build it on your own machine

This is optional and comes with a plan. The course pack brings the starting files, a ready container and a check for every lesson. You need only Docker and git, plus your own AI coding agent if you want a tutor.

What you learn

The model already reads English. You teach it your labels in minutes.

You take a small pretrained transformer from the Hugging Face Hub and adapt it to one job: reading a bank customer's message about their card and naming the request. You see what the model already knows, how a tokenizer turns text into numbers and how scores become a label. Then you measure the model on real labelled messages, fine-tune it in a few minutes on a laptop CPU, judge the result on a test set and use it. You need Python and the basics of training a network in PyTorch. No GPU and no account.

  • Pretrained Models and the Hub. A model someone else trained on a huge amount of text, published with its card and licence, downloaded by name and reused instead of trained from nothing.
  • From Text to a Label. What happens between a sentence and an answer: a tokenizer turns text into token IDs, the model turns them into vectors, a small head turns one vector into a score per class.
  • Measure Before and After. Labelled data split three ways, a baseline taken before any training, and a final judgement on a test set with results per class and a look at the mistakes.
  • Fine-Tuning as Adaptation. A short, seeded training run that keeps what the model learned from pretraining and adds your classes, with far less data and time than training from random weights.

Lessons

Where it fits

Course 4 of 5 on the Machine Learning Engineer path.

How our courses are made Report a mistake