recurrent neural networks #define evaluate step def evaluate(modeliteratorcriterion)epoch_loss,epoch_acc,epoch_denom , , model eval(with torch no_grad()for batch in iteratortexttext_lengths batch text predictions model(texttext_lengthssqueeze( loss criterion(predictionsbatch label float()acc accuracy(predictionsbatch labelepoch_loss +loss item(epoch_acc +acc item(epoch_denom +len(batchreturn epoch_loss/epoch_denomepoch_accepoch_denom #define optimizerloss funciton and load to gpu optimizer optim adam(model parameters()criterion nn bcewithlogitsloss(model model to(devicecriterion criterion to(device#similar to previous exercisewe deifne our accuracy function def accuracy(predsy)rounded_preds torch round(torch sigmoid(preds)correct (rounded_preds =yfloat(acc correct sum(return acc