def decode(seqIdx, idxToToken, delim=None, stopAtEnd=True):
  """
  Given seqIdx (list of token_ixs), decode to a sentence.  
  """
  tokens = []
  for idx in seqIdx:
    tokens.append(idxToToken[idx])
    if stopAtEnd and tokens[-1] == '<END>':
      break
  if delim is None:
    return tokens
  else:
    return delim.join(tokens)