I am unable to get accuracy and validation loss getting print.
Here is the code
def training_step(self,batch,batch_idx):
input_ids,attention_mask,label=batch
out=self.forward(input_ids,attention_mask)
loss=torch.nn.functional.cross_entropy(out,label,self.class_weights)
pred=torch.max(out,dim=1)[1]
return {'loss':loss}
def validation_step(self,batch,batch_idx):
input_ids,attention_mask,label=batch
out=self(input_ids,attention_mask)
loss=torch.nn.functional.cross_entropy(out,label,self.class_weights)
pred=torch.max(out,dim=1)[1]
return {'val_loss':loss,'pred':pred.detach(),'label':label.detach()}
def validaton_epoch_end(self,outputs):
avg_loss = torch.stack([x['val_loss'] for x in outputs]).mean()
pred=torch.cat([x['pred'] for x in outputs])
label=torch.cat([x['label'] for x in outputs])
acc=self.metric(pred,label)
print('accuracy: ', acc)
model = OurModel().to(device)
Trainer
trainer = Trainer(max_epochs=5, min_epochs=1, auto_lr_find=False, auto_scale_batch_size=False,tpu_cores=1,precision=16,
progress_bar_refresh_rate=10,
)
trainer.tune(model)
trainer.fit(model)
What I want is to print validation accuracy and loss after each epoch.
Here is screenshot of what I am getting right now
I also tried this
def training_step(self,batch,batch_idx):
input_ids,attention_mask,label=batch
out=self.forward(input_ids,attention_mask)
loss=torch.nn.functional.cross_entropy(out,label,self.class_weights)
pred=torch.max(out,dim=1)[1]
train_acc=self.metric(pred,label)
self.log('train/acc', train_acc, on_epoch=True)
self.log('train/loss', loss, on_epoch=True)
return loss
def validation_step(self,batch,batch_idx):
input_ids,attention_mask,label=batch
out=self(input_ids,attention_mask)
loss=torch.nn.functional.cross_entropy(out,label,self.class_weights)
pred=torch.max(out,dim=1)[1]
valid_acc=self.metric(pred,label)
self.log('vall/acc', valid_acc, on_epoch=True)
self.log('vall/loss', loss, on_epoch=True)
return loss