我正在使用hugginface库来训练一个关于分类问题的bert模型。
model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=10)
def training_step(self, batch, batch_nb):
sequence, label = batch
input_ids, attention_mask, labels = self.prepare_batch(sequence=sequence, label=label)
loss = self.model(input_ids=input_ids,
attention_mask=attention_mask,
labels=labels)
tensorboard_logs = {'train_loss': loss}
我在培训开始前收到以下错误:
in training_step
closure_loss = closure_loss / self.trainer.accumulate_grad_batches
TypeError: unsupported operand type(s) for /: 'SequenceClassifierOutput' and 'int'
我用的是火焰 lightning
1条答案
按热度按时间fcg9iug31#
调用self.model()返回一个 SequenceClassifierOutput 类型的对象。要访问loss,需要调用它的loss属性:
替换
由