如何获得 Huggingface.transformers Trainer 每个时期或步骤的准确性验证?

问题描述 投票:0回答:1

我正在研究变压器模型,我有这样的代码

# define the metrics

import numpy as np
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, classification_report

def compute_metrics(p):
    pred, labels = p
    pred = np.argmax(pred, axis=1)

    report = classification_report(labels, pred, digits=4)
    acc = accuracy_score(y_true=labels, y_pred=pred)
    rec = recall_score(y_true=labels, y_pred=pred, average='micro')
    prec = precision_score(y_true=labels, y_pred=pred, average='micro')
    f1 = f1_score(y_true=labels, y_pred=pred, average='micro')

    print("Classification Report:\n{}".format(report))
    return {"accuracy": acc, "precision": prec, "recall": rec, "f1": f1}

from transformers import TrainingArguments, Trainer
from transformers import AutoModelForSequenceClassification

# Get the base model and configuration
model = AutoModelForSequenceClassification.from_pretrained(
    model_chkpt,
    num_labels=7,
    id2label=id2label,
    label2id=label2id,
    ignore_mismatched_sizes=True
)

output_dir = "indonesian-emotion-distilbert-base-cased-finetuned" # name directory
training_args = TrainingArguments(
        output_dir=output_dir,
        evaluation_strategy="epoch",
        save_strategy="epoch",
        learning_rate=1e-5,
        per_device_train_batch_size=16,
        per_device_eval_batch_size=16,
        num_train_epochs=5,
        warmup_ratio=0.01,
        weight_decay=0.01,
        load_best_model_at_end=True,
        metric_for_best_model="accuracy",
        push_to_hub=True)

trainer = Trainer(
    model=model,
    args=training_args,
    tokenizer=tokenizer,
    train_dataset=tokenized_train_data,
    eval_dataset=tokenized_test_data,
    compute_metrics=compute_metrics,
)

trainer.train()

在评估结果中我得到了这样的结果

训练损失、纪元步骤验证损失准确率精确召回率 F1

这个矩阵验证或训练的准确性是多少?

如果是训练精度矩阵,如何得到验证精度矩阵

huggingface-transformers bert-language-model evaluation
1个回答
0
投票

我在这里也面临着同样的问题。训练器类输出的形式为 历元、训练损失、验证损失、准确度、F1、精确度、召回率 我还需要每个时期的训练准确性,以便绘制(训练和验证准确性)和(训练和验证损失)。有人可以帮助我吗

© www.soinside.com 2019 - 2024. All rights reserved.