code: def attend(input_mat, state, w1dt):
      global attention_w2
      global attention_v
      w2 = dy.parameter(attention_w2)
      v = dy.parameter(attention_v)
  
      # input_mat: (encoder_state x seqlen) => input vecs concatenated as cols
      # w1dt: (attdim x seqlen)
      # w2dt: (attdim x attdim)
      w2dt = w2 * dy.concatenate(list(state.s()))
      # att_weights: (seqlen,) row vector
      unnormalized = dy.transpose(
          v * dy.tanh(dy.colwise_add(w1dt, w2dt))
      )
      att_weights = dy.softmax(unnormalized)
      # context: (encoder_state)
      context = input_mat * att_weights
      return context
  
file_path: dynet/examples/sequence-to-sequence/attention.py
imports: import dynet
  import random
label_desc: Use image node_id 4 for calling a global function with example usage: attend(input_mat, state, w1dt) and returns: context