Hi, trying to calculate Accuracy over the whole data.
The error is because output of the model is 53 and target tensor size is 16(the batch size)
This is the code:
for step,batch in enumerate(val_loader):
ids = batch['input_ids'].to(device, dtype = torch.long)
mask = batch['attention_mask'].to(device, dtype = torch.long)
token_type_ids = batch['token_type_ids'].to(device, dtype = torch.long)
targets = batch['labels'].to(device)
with torch.no_grad():
logits=model(ids,mask,token_type_ids)
loss=loss_f(logits,targets)
val_loss.append(loss.item())
preds=torch.argmax(logits,dim=1).flatten()
**val_acc_=(preds==targets).cpu().numpy().mean()*100** # this is the error
val_accuracy.append(val_acc_.item())
val_loss=np.mean(val_loss)
val_acc=np.mean(val_accuracy)
return val_loss,val_acc
How do i solve that? or is there any other way to calculate accuracy?