# My model has 0.7142 Accuracy in 99% of the time while my loss value jumps around

I am using a lstm as a classifier for timeseries data for 3 classes. I print out my predictions and labels at the end with my loss and accuracy. No matter if my Loss is 0.1 or 1.0 my accuracy is almost always 0.7142.

I am wondering if I calculated loss and accuracy correctly in my model or if this is just a problem about hyperparamter tuning. I am under a lot of time pressure so if someone could help me I would be very thankful.

My validation loop looks as follows.
EDIT: I am using CrossEntropyLoss() as criterion

``````for i, (inputs, labels) in enumerate(valloader):

y_pred = model(inputs)
_,prediction2 = torch.max(y_pred, 1)
labels = labels.type_as(y_pred)
labels = labels.long()
val_loss = criterion(y_pred, labels)
running_val_loss += val_loss.item()

for x in range(len(labels)):
y_true_list.append(labels[x].item())
for x in range(len(prediction2)):
y_pred_list.append(prediction2[x].item())

total += labels.size(0)
correct += (prediction2 == labels).sum().item()

#getting output for metric calc correct
softmax = nn.Softmax(dim=1)
probability = softmax(y_pred)

for x in range(len(probability)):
probability_each = probability[x].detach().numpy()
prob_softmax.append(probability_each)
validation_losses.append(val_loss_mean)

accuracy = (correct/total)
validation_accuracys.append(accuracy)

print("Y True and Y Pred :",y_true_list, y_pred_list)
print(f'Fold {fold}: For Epoche {epoch} the Loss is {val_loss_mean} and the Acc is {accuracy}')

``````

I guess `0.7142` would correlate to the potential class imbalance in your `Dataset`?
Could you check, if your model is predicting the same class for all samples?

That is what I thought as well but it does not. I am printing the true label list and the predicted label list at the end and my model does not always predict the same class.

Maybe I found one problem in my model which causes this. Maybe my model does not know when a sequence inside a batch ends and the next one starts and it is treating it like a whole sequence? I am having trouble understanding how to make my model effectively use batch training. Different sources say different things about implementing hidden state reset and none work for me.