Skip to content

Guide · Open source

How to use Transformers-Tutorials: notebooks for BERT, DETR and Donut

Updated · written with AI from the project's own documentation and checked against our catalogue data

Transformers-Tutorials is a set of Jupyter notebooks by Niels Rogge, a Hugging Face contributor, that demonstrate the Transformers library. Each demo focuses on one model, such as BERT, DETR, CLIPSeg or Donut, and shows how to run inference or fine-tune it on a dataset. This guide explains how to get the notebooks, which ones to start with, and what you need installed before you run them.

Transformers-TutorialsNielsRogge/Transformers-Tutorials · ★ 11.8k · MIT

Quick start

  1. 1Check prerequisites. Confirm you have Python, PyTorch and the Hugging Face Transformers library, or plan to use Google Colab.
  2. 2Clone the repository. Run git clone on the NielsRogge/Transformers-Tutorials repository to download the notebooks.
  3. 3Choose a demo. Pick the model and task closest to your goal from the list of demos in the README.
  4. 4Open the notebook. Open the notebook in Jupyter Notebook, or use the Google Colab badge to run it in the browser.
  5. 5Run and adapt. Run the cells in order, then replace the example data with your own dataset when you are ready to fine-tune.

What you need before you start

The README lists four prerequisites: Python, Jupyter Notebook or Google Colab, PyTorch, and the Hugging Face Transformers library. All of the demos are implemented in PyTorch, so the repository is not a fit if you need TensorFlow or JAX examples.

The README recommends the Hugging Face free course first if you are new to Hugging Face or Transformers. It introduces architectures such as BERT, GPT-2, T5 and BART.

  • Python
  • Jupyter Notebook or Google Colab
  • PyTorch
  • Hugging Face Transformers library

Get the notebooks on your computer

The install method is clone-and-build: copy the repository to your machine with git. The notebooks are then ready to open in Jupyter. If you prefer no local setup, you can skip cloning and use the Google Colab badge next to each demo instead.

git clone https://github.com/NielsRogge/Transformers-Tutorials

Pick a demo that matches your task

The README groups demos by model. Each entry names the task and the Transformers class it uses, so you can find the one closest to your goal. Examples include inference with ConditionalDetrForObjectDetection, fine-tuning BertForSequenceClassification for multi-label text classification, and zero-shot image segmentation with CLIPSeg.

Document AI users will find several Donut notebooks, covering document image classification, document visual question answering (DocVQA) and document parsing. DiT has a notebook for document image classification.

  • Inference: run a pretrained model on your input, such as audio classification with ASTForAudioClassification.
  • Fine-tuning: train a model further on a dataset, such as the balloon dataset used for DETR and Conditional DETR.
  • Evaluation: measure a model, such as DETR on the COCO detection 2017 validation set.
  • Visualization: inspect model internals, such as self-attention in DINO.

Run a notebook in Google Colab or Jupyter

Every demo in the README links to a Google Colab badge. Clicking it opens that notebook in Colab, so you can run it without local setup. To run locally, open the cloned folder in Jupyter Notebook and select the notebook for your model. Each notebook lives in a folder named after its model, such as BERT, DETR or Donut.

What people use it for

  • Run zero-shot image segmentation with CLIPSeg from a text prompt.
  • Fine-tune DETR on a custom object detection dataset, such as the balloon example in the repository.
  • Classify document images or answer questions over documents with Donut.
  • Fine-tune BERT for named entity recognition or multi-label text classification.

Frequently asked questions

Is Transformers-Tutorials free to use?

The repository is released under the MIT licence, as shown on its GitHub page. You can use, copy and modify the notebooks under that licence.

Do I need to install anything to try it?

No local setup is needed for the demos that have a Google Colab badge. Clicking the badge opens the notebook in Colab. To run notebooks locally, you need Python, Jupyter, PyTorch and Hugging Face Transformers.

Are the examples in PyTorch or TensorFlow?

The README says all of the demos are implemented in PyTorch. It does not list TensorFlow or JAX examples.

Should I learn Transformers before using this repository?

The README recommends Hugging Face's free course first if you are not familiar with HuggingFace or Transformers. The course covers the core architectures and libraries the demos rely on.

Is this a production library I can install with pip?

No. It is a set of demos rather than a maintained package or service. Use it as a starting point and check the Transformers library itself for production code.

What are alternatives to Transformers-Tutorials?

The repository's comparable projects include huggingface/notebooks, huggingface/transformers and fastai/course-v3. Choose huggingface/transformers for the library itself and huggingface/notebooks for official Hugging Face notebook examples.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Transformers-Tutorials suits developers and students who already know some Python and machine learning and want runnable PyTorch examples for BERT, DETR, Donut and similar models. Complete beginners should start with the Hugging Face course, and anyone needing a maintained production library or TensorFlow or JAX examples should look elsewhere.

Install options & downloads