2

I've been fine-tuning a Model from HuggingFace via the Trainer-Class. I went through the Training Process via trainer.train() and also tested it with trainer.evaluate().

My question is how I can run the Model on specific data. In case of a classification text I'm looking for sth like this:

trainer.predict('This text is about football')
output = 'Sports'

Do I need to save the Model first or is there a command I can use directly? What's the most simple way on running the fine-tuned Model?

Infomagier
  • 171
  • 1
  • 3
  • 9

1 Answers1

1

Here is an example: https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_xnli.py#L415

It shows you the way to train, evaluate, and predict with the class transformers.Trainer

Suneburg
  • 41
  • 2
  • 1
    Thank you a lot! Is there also a way to predict a single datarow (with only Features/no Label) instead of a whole dataset? – Infomagier Oct 17 '22 at 13:21
  • 1
    @Infomagier If you relay on the transformers.Trainer class, you can make a dataset with only one sample (maybe with a fake label). Another way to accomplish you goal is to implement the training and evaluating procedure for your self. Check https://huggingface.co/course/chapter3/4?fw=pt for example. – Suneburg Oct 20 '22 at 09:07