Unverified Commit 8a303f52 authored by raghavanone's avatar raghavanone Committed by GitHub
Browse files

Sanity check the type of id2label and label2id arguments of from_pretrained...

Sanity check the type of id2label and label2id arguments of from_pretrained for TokenClassification models (#21490)

* Sanity check the type of id2label and label2id arguments of from_pretrained for TokenClassification models

* Incorporate PR feedbacks

* Incorporate PR feedbacks
parent 28ec07d8
......@@ -313,7 +313,11 @@ class PretrainedConfig(PushToHubMixin):
self.finetuning_task = kwargs.pop("finetuning_task", None)
self.id2label = kwargs.pop("id2label", None)
self.label2id = kwargs.pop("label2id", None)
if self.label2id is not None and not isinstance(self.label2id, dict):
raise ValueError("Argument label2id should be a dictionary.")
if self.id2label is not None:
if not isinstance(self.id2label, dict):
raise ValueError("Argument id2label should be a dictionary.")
num_labels = kwargs.pop("num_labels", None)
if num_labels is not None and len(self.id2label) != num_labels:
logger.warning(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment