code: def decode(dec_lstm, vectors, output):
      output = [EOS] + list(output) + [EOS]
      output = [char2int[c] for c in output]
  
      w = dy.parameter(decoder_w)
      b = dy.parameter(decoder_b)
      w1 = dy.parameter(attention_w1)
      input_mat = dy.concatenate_cols(vectors)
      w1dt = None
  
      last_output_embeddings = output_lookup[char2int[EOS]]
      s = dec_lstm.initial_state().add_input(
          dy.concatenate(
              [dy.vecInput(STATE_SIZE * 2), last_output_embeddings]
          )
      )
      loss = []
  
      for char in output:
          # w1dt can be computed and cached once for the entire decoding phase
          w1dt = w1dt or w1 * input_mat
          vector = dy.concatenate(
              [attend(input_mat, s, w1dt), last_output_embeddings]
          )
          s = s.add_input(vector)
          out_vector = w * s.output() + b
          probs = dy.softmax(out_vector)
          last_output_embeddings = output_lookup[char]
          loss.append(-dy.log(dy.pick(probs, char)))
      loss = dy.esum(loss)
      return loss
  
file_path: dynet/examples/sequence-to-sequence/attention.py
imports: import dynet
  import random
label_desc: Use image node_id 5 for calling a global function with example usage: decode(dec_lstm, vectors, output) and returns: loss