from transformers import AutoModelForSequenceClassification # Model id to load the tokenizer model_id = "bert-base-uncased" # Prepare model labels - useful for inference labels = tokenized_dataset["train"].features["labels"].names num_labels = len(labels) label2id, id2label = dict(), dict() for i, label in enumerate(labels): label2id[label] = str(i) id2label[str(i)] = label # Download the model from huggingface.co/models model = AutoModelForSequenceClassification.from_pretrained( model_id, num_labels=num_labels, label2id=label2id, id2label=id2label )