How to write a custom configuration for hugging face model for Token Classification

you don’t need to pass id2label ,label2id,num_labels to your custom config these are special keywords so you can just do:

class BertClassifierConfig(PretrainedConfig):
    model_type="BertForTokenClassification"

bert_model="bert-cased-base" #etc
configuration = BertClassifierConfig.from_pretrained(bert_model, id2label=label2id, num_labels=len(label2id), label2id= label2id)
model = BertForTokenClassification.from_pretrained(bert_model, config=configuration)

But if you need to pass some other kwargs through your config I don’t know how either.

1 Like