-
Notifications
You must be signed in to change notification settings - Fork 486
Open
Description
02-NLP Tasks ---> 08-transformers_slolution ---> classificaion_demo.ipynb
问题定位
f1 = f1_metric.compute(predictions=predictions, references=labels)
报错信息
return {"f1": float(score) if score.size == 1 else score}
AttributeError: 'float' object has no attribute 'size'
原因分析
def _compute(self, predictions, references, labels=None, pos_label=1, average="binary", sample_weight=None):
score = f1_score(
references, predictions, labels=labels, pos_label=pos_label, average=average, sample_weight=sample_weight
)
return {"f1": float(score) if score.size == 1 else score}
'float' object has no attribute 'size', 在二分类任务中,当 average="binary" 时,f1_score 返回一个单一的 float 值,
而不是 NumPy 数组,因此 score.size 会触发错误。
修改返回值
return {"f1": float(score)}
Metadata
Metadata
Assignees
Labels
No labels