ValueError: too many dimensions ‘str’

使用Bert进行训练时,报错如题。具体如下:

1
2
3
4
5
ValueError: too many dimensions 'str'

The above exception was the direct cause of the following exception:

ValueError: Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' 'truncation=True' to have batched tensors with the same length. Perhaps your features (`labels` in this case) have excessive nesting (inputs type `list` where type `int` is expected).

解决方案

labels应该是str 类型的,改成int即可

1
labels=[int(label) for label in labels]