from transformers import AutoModelForSequenceClassification, DataCollatorWithPadding from huggingface_hub import HfFolder # create label2id, id2label dicts for nice outputs for the model labels = tokenized_datasets["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 # define training args training_args = DistillationTrainingArguments( output_dir=repo_name, num_train_epochs=7, per_device_train_batch_size=128, per_device_eval_batch_size=128, fp16=True, learning_rate=6e-5, seed=33, # logging & evaluation strategies logging_dir=f"{repo_name}/logs", logging_strategy="epoch", # to get more information to TB evaluation_strategy="epoch", save_strategy="epoch", save_total_limit=2, load_best_model_at_end=True, metric_for_best_model="accuracy", report_to="tensorboard", # push to hub parameters push_to_hub=True, hub_strategy="every_save", hub_model_id=repo_name, hub_token=HfFolder.get_token(), # distilation parameters alpha=0.5, temperature=4.0 ) # define data_collator data_collator = DataCollatorWithPadding(tokenizer=tokenizer) # define model teacher_model = AutoModelForSequenceClassification.from_pretrained( teacher_id, num_labels=num_labels, id2label=id2label, label2id=label2id, ) # define student model student_model = AutoModelForSequenceClassification.from_pretrained( student_id, num_labels=num_labels, id2label=id2label, label2id=label2id, )