DEV Community

Cover image for AI enthusiasm #1 - Finetune text-classification AIs, codeless🤯
Astra Bertelli
Astra Bertelli

Posted on • Updated on

AI enthusiasm #1 - Finetune text-classification AIs, codeless🤯

Finetune text-classification models effortlessly🤗

Hi AI enthusiasts!
In today's tutorial, we are going to explore the simplest, yet most effective, way to fine-tune a pretrained text-classification model on new data!

We will do it completely codeless, so that this can be done even by beginners😊

1. Set up you Hugging Face account

The only requirement for this tutorial is to have an Hugging Face account. In order to get it:

  • Go to Hugging Face from the link above and click on the Sign up bottom. Alternatively, you can directly follow this link.
  • Provide e-mail address and password
  • Follow the instructions as you are prompted by the registration procedure

2. Create an Autotrain space on Hugging Face

To create the space, just make sure you click this link: you will be prompted to name your space. I think I will call it "Pallas-Cat", what about you?😼

3. Find a suitable dataset for text classification

You can find plenty of datasets on Hugging Face, and you can also create your own. For today, we'll stick with an already established dataset, dair-ai/emotion, for emotion recognition from text.

4. Find a suitable model for text-classification

Again, there are tons of model on Hugging Face Hub, and you can choose among lots of them in your Autotrain space. Nevertheless, we will stick with a basic one, google-bert/bert-base-uncased.

5. Finetune the model

Now that everything is set up, we're ready to finetune bert-base-uncased on the emotion dataset:

  • First of all, make sure to choose the right Project name, Task and Base Model from the Autotrain interface
  • Secondly, in the Dataset section, click on "Hub Dataset", type dair-ai/emotion in the homonymous field and write "train" (without quotation marks) in the "Train split" field, whereas write "validation" (without quotation marks) in the "Valid split" one.
  • Last but not least, make sure to set "mixed_precision" to "no" in the training parameters box on the right side of Autotrain interface (if you are not running on a GPU-powered HF space)
  • In the "Column mapping" field, make sure to replace "label":"target" with "label":"label".

Ok, we are ready!🥰

Just click on "Start training" and wait until the magic is done: you will see a model card in your account, named with the Project name specified at the beginning. You will be also able to play around a little bit with the Inference API widget that usually comes along with every model.

So, congrats! You finetuned and deployed your first text-classification model, with no code and almost-zero effort!🎉🥳

Stay tuned for other tutorials coming soon!

Top comments (0)