Fine turning of Bert/DistilBert models don’t show the validation metrics during training even though evaluation_strategy in TrainingArguments is set to epoch/steps and compute metrics are defined as follows.
def compute_metrics(p):
pred, labels = p
pred = np.argmax(pred, axis=1)
accuracy = accuracy_score(y_true=labels, y_pred=pred)
recall = recall_score(y_true=labels, y_pred=pred)
precision = precision_score(y_true=labels, y_pred=pred)
f1 = f1_score(y_true=labels, y_pred=pred)
return {“accuracy”: accuracy, “precision”: precision, “recall”: recall, “f1”: f1}
training_args = TrainingArguments(
output_dir=’/home/dxr8k83/CatelogBert_V1.1/out/’,
num_train_epochs=1,
per_device_train_batch_size=32,
per_device_eval_batch_size=16,
warmup_steps=10,
weight_decay=0.01,
learning_rate = 5e-04,
logging_dir=’./logs’,
logging_steps=10,
evaluation_strategy=‘steps’,
load_best_model_at_end = True,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=val_dataset,
compute_metrics = compute_metrics,
)
trainer.train()