Huggingface BERT SequenceClassification-ValueError:太多值无法解包预期2

问题描述

两个类别模型的类别标签为0、1、0、0等。只有一个 每个输入序列的标签标签python列表中设置并转换为 火炬张量(从csv文件读取-直截了当)。

其值:张量(0) 其形状显示为:torch.Size([])

当我创建批次等并在模型(拥抱面序列分类模型)中设置参数时

对于每次批处理迭代,

   b_input_ids = batch[0].to(device)
   b_input_mask = batch[1].to(device)
   b_token_type_ids = batch[2].to(device)
   b_labels = batch[3].to(device)

然后设置为模型(作为训练的一部分)

loss,logits = model(b_input_ids,attention_mask=b_input_mask,token_type_ids=b_token_type_ids,labels=b_labels)

错误消息如下

    ValueError                                
    
        Traceback (most recent call last)
        
        <ipython-input-17-b3a36df2f659> in <module>()
             89                              attention_mask=b_input_mask,90                              token_type_ids=b_token_type_ids,---> 91                              labels=b_labels)
             92 
             93         # Accumulate the training loss over all of the batches so that we can
        
ValueError: too many values to unpack (expected 2)

这是我几天前能够使用和训练的代码。 (我有一个保存的模型)。 错误消息(我假设为)可能与大小等有关。

有人遇到类似的问题吗?谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)