2021-02-22

在训练BERT预训练模型过程中,出现了一个TypeError。在计算损失时,检查tnews_pred是否为None导致错误,因为NoneType不能与其他类型进行比较。这可能是由于模型的预测输出未正确初始化或在某个批次的数据中缺失导致的。
摘要由CSDN通过智能技术生成
TypeError                                 Traceback (most recent call last)
/mnt/train.py in <module>
    251     pretrained_model = './bert_pretrain_model'
    252     tokenizer_model = './bert_pretrain_model'
--> 253     train(batchSize=16, device='cuda:0', lr=0.0001, use_dtp=True, pretrained_model=pretrained_model, tokenizer_model=tokenizer_model, weighted_loss=True)

/mnt/train.py in train(epochs, batchSize, lr, device, accumulate, a_step, load_saved, file_path, use_dtp, pretrained_model, tokenizer_model, weighted_loss)
    108                 ocemotion_kpi = 0.1 if len(train_ocemotion_pred_list) == 0 else train_ocemotion_correct / len(train_ocemotion_pred_list)
    109                 current_loss = loss_object.compute_dtp(tnews_pred, ocnli_pred, ocemotion_pred, tnews_gold, ocnli_gold,
--> 110                                                    ocemotion_gold, tnews_kpi, ocnli_kpi, ocemotion_kpi)
    111             else:
    112                 current_loss = loss_object.compute(tnews_pred, ocnli_pred, ocemotion_pred, tnews_gold, ocnli_gold, ocemotion_gold)

/mnt/calculate_loss.py in compute_dtp(self, tnews_pred, ocnli_pred, ocemotion_pred, tnews_gold, ocnli_gold, ocemotion_gold, tnews_kpi, ocnli_kpi, ocemotion_kpi, y)
     49     def compute_dtp(self, tnews_pred, ocnli_pred, ocemotion_pred, tnews_gold, ocnli_gold, ocemotion_gold, tnews_kpi=0.1, ocnli_kpi=0.1, ocemotion_kpi=0.1, y=0.5):
     50         res = 0
---> 51         if tnews_pred != None:
     52             res += self.tnews_loss(tnews_pred, tnews_gold) * self._calculate_weight(tnews_kpi, y) if self.weighted else self.loss(tnews_pred, tnews_gold) * self._calculate_weight(tnews_kpi, y)
     53         if ocnli_pred != None:

TypeError: ne() received an invalid combination of arguments - got (NoneType), but expected one of:
 * (Tensor other)
      didn't match because some of the arguments have invalid types: (!NoneType!)
 * (Number other)
      didn't match because some of the arguments have invalid types: (!NoneType!)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值