code: def eval_model(model, valid):
      model.eval()
      args = model.args
      total_loss = 0.0
      unroll_size = model.args.unroll_size
      criterion = nn.CrossEntropyLoss(size_average=False)
      hidden = model.init_hidden(1)
      N = (len(valid[0]) - 1) // unroll_size + 1
      for i in range(N):
          x = valid[0][i * unroll_size : (i + 1) * unroll_size]
          y = valid[1][i * unroll_size : (i + 1) * unroll_size].view(-1)
          x, y = Variable(x, volatile=True), Variable(y)
          hidden = (
              (Variable(hidden[0].data), Variable(hidden[1].data))
              if args.lstm
              else Variable(hidden.data)
          )
          output, hidden = model(x, hidden)
          loss = criterion(output, y)
          total_loss += loss.item()  # loss.data[0]
      avg_loss = total_loss / valid[1].numel()
      ppl = np.exp(avg_loss)
      return ppl
  
imports: import sys
  import os
  import argparse
  import time
  import random
  import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.autograd import Variable
  import sru
label_desc: Use image node_id 4 for calling a global function with example usage: eval_model(model, valid) and returns: ppl