TRL documentation

Sentiment Examples

You are viewing v0.4.7 version. A newer version v0.12.1 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Sentiment Examples

The notebooks and scripts in this examples show how to fine-tune a model with a sentiment classifier (such as lvwerra/distilbert-imdb).

Here’s an overview of the notebooks and scripts in the trl repository:

File Description Colab link
gpt2-sentiment.ipynb Fine-tune GPT2 to generate positive movie reviews. Open In Colab
gpt2-sentiment-control.ipynb Fine-tune GPT2 to generate movie reviews with controlled sentiment. Open In Colab
gpt2-sentiment.py Same as the notebook, but easier to use to use in multi-GPU setup. x
t5-sentiment.py Same as GPT2 script, but for a Seq2Seq model (T5). x

Installation

pip install trl
#optional: wandb
pip install wandb

Note: if you don’t want to log with wandb remove log_with="wandb" in the scripts/notebooks. You can also replace it with your favourite experiment tracker that’s supported by accelerate.

Launch scripts

The trl library is powered by accelerate. As such it is best to configure and launch trainings with the following commands:

accelerate config # will prompt you to define the training configuration
accelerate launch scripts/gpt2-sentiment.py # launches training