Home

Awesome

Transformers Notebooks

This repository contains the example code from our O'Reilly book Natural Language Processing with Transformers:

<img alt="book-cover" height=200 src="images/book_cover.jpg" id="book-cover"/>

Getting started

You can run these notebooks on cloud platforms like Google Colab or your local machine. Note that most chapters require a GPU to run in a reasonable amount of time, so we recommend one of the cloud platforms as they come pre-installed with CUDA.

Running on a cloud platform

To run these notebooks on a cloud platform, just click on one of the badges in the table below:

<!--This table is automatically generated, do not fill manually!-->
ChapterColabKaggleGradientStudio Lab
IntroductionOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Text ClassificationOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Transformer AnatomyOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Multilingual Named Entity RecognitionOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Text GenerationOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
SummarizationOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Question AnsweringOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Making Transformers Efficient in ProductionOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Dealing with Few to No LabelsOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Training Transformers from ScratchOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
Future DirectionsOpen In ColabKaggleGradientOpen In SageMaker Studio Lab
<!--End of table-->

Nowadays, the GPUs on Colab tend to be K80s (which have limited memory), so we recommend using Kaggle, Gradient, or SageMaker Studio Lab. These platforms tend to provide more performant GPUs like P100s, all for free!

Running on your machine

To run the notebooks on your own machine, first clone the repository:

git clone https://github.com/nlp-with-transformers/notebooks
cd notebooks-test

Next, you'll need to install a few packages that depend on your operating system and hardware:

Once you have install the above requirements, create a virtual environment and install the remaining Python dependencies:

conda create -n book python=3.8 -y && conda activate book
from install import *
install_requirements()
# Use the following to run Chapter 7
# install_requirements(is_chapter7)