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!)
2021-02-22
最新推荐文章于 2022-03-24 10:45:25 发布
在训练BERT预训练模型过程中,出现了一个TypeError。在计算损失时,检查tnews_pred是否为None导致错误,因为NoneType不能与其他类型进行比较。这可能是由于模型的预测输出未正确初始化或在某个批次的数据中缺失导致的。
摘要由CSDN通过智能技术生成