当输出是一个热编码时,如何计算Roberta模型的F1分数



我想根据测试数据计算我的模型的F1分数。我有12个类,所以实际输出可能是这样的:

[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]

预测的输出可能是这样的:

[0.0557, 0.0952, 0.0811, 0.1133, 0.0613, 0.0594, 0.1092, 0.0866, 0.0880, 0.0882, 0.0559, 0.1061]

加起来为1的概率。

如何用这个计算F1分数?

您只需要使用torch.argmax(input, dim, keepdim=False):

predictions = torch.argmax(model_outputs, dim=1)

然后,如果你想要一个ho版本,你可以使用torch.nn.functional.one_hot

one_hot_predictions = torch.nn.functional.one_hot(predictions)

从那里,你可以根据的要求计算F1的分数

最新更新