Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify number of target classes for TFRobertaSequenceClassification?

I have a text classification task at hand and I want to use RoBERTa pre-trained model from the transformers python library.

As per the documentation of TFRobertaForSequenceClassification to train we have to use,

from transformers import RobertaTokenizer, TFRobertaForSequenceClassification

tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
model = TFRobertaForSequenceClassification.from_pretrained('roberta-base')

model.compile('adam', loss='sparse_categorical_crossentropy')
model.fit(x, y)

So where should I specify the number of target labels for sequence classification?

like image 493
user_12 Avatar asked Oct 24 '25 07:10

user_12


1 Answers

You can use num_labels parameter.

model = TFRobertaForSequenceClassification.from_pretrained('roberta-base', num_labels = 5)

ref: https://huggingface.co/transformers/main_classes/configuration.html

like image 157
Zabir Al Nazi Avatar answered Oct 26 '25 23:10

Zabir Al Nazi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!