class_docstr: Defines end to end MatchLSTM and Answer_Pointer network for Reading Comprehension
class_docstr_tok: ["Defines","end","to","end","MatchLSTM","and","Answer_Pointer","network","for","Reading","Comprehension"]
docstr: Function to run the match_lstm pass in both forward and reverse directions
  
  Args:
  reverse: Boolean indicating whether to unroll in reverse directions
docstr_tok: ["Function","to","run","the","match_lstm","pass","in","both","forward","and","reverse","directions","Args",":","reverse",":","Boolean","indicating","whether","to","unroll","in","reverse","directions"]
code: def unroll_with_attention(self, reverse=False):
      """
      Function to run the match_lstm pass in both forward and reverse directions
  
      Args:
      reverse: Boolean indicating whether to unroll in reverse directions
  
      """
      # Intitialze first hidden_state with zeros
      h_r_old = tf.constant(
          np.zeros([self.batch_size, self.hidden_size, 1]),
          dtype=tf.float32,
      )
      final_state_list = []
  
      for i in range(self.max_para):
          if not reverse:
              encoded_paraslice = tf.gather(
                  self.encoded_para, indices=i, axis=1
              )
          else:
              encoded_paraslice = tf.gather(
                  self.encoded_para_reverse, indices=i, axis=1
              )
  
          W_p_expanded = tf.tile(self.W_p, [self.batch_size, 1, 1])
          W_q_expanded = tf.tile(self.W_q, [self.batch_size, 1, 1])
          W_r_expanded = tf.tile(self.W_r, [self.batch_size, 1, 1])
          w_lr_expanded = tf.tile(self.w_lr, [self.batch_size, 1, 1])
          b_p_expanded = tf.tile(self.b_p, [self.batch_size, 1, 1])
  
          int_sum = (
              tf.matmul(
                  W_p_expanded, tf.expand_dims(encoded_paraslice, 2)
              )
              + tf.matmul(W_r_expanded, h_r_old)
              + b_p_expanded
          )
  
          int_sum_new = tf.matmul(
              int_sum, tf.expand_dims(self.ques_mask, 1)
          )
  
          int_sum1 = tf.matmul(
              W_q_expanded,
              tf.transpose(self.encoded_question, [0, 2, 1]),
          )
  
          self.G_i = tf.nn.tanh(
              int_sum_new + int_sum1
          ) + tf.expand_dims(self.c_p * self.ques_mask, 1)
  
          # Attention Vector
          self.attn = tf.nn.softmax(tf.matmul(w_lr_expanded, self.G_i))
  
          z1 = encoded_paraslice
  
          z2 = tf.squeeze(
              tf.matmul(
                  tf.transpose(self.encoded_question, [0, 2, 1]),
                  tf.transpose(self.attn, [0, 2, 1]),
              ),
              axis=2,
          )
  
          z_i_stacked = tf.concat([z1, z2], 1)
          if i == 0:
              h_r_old, cell_state_old = self.match_lstm_cell(
                  z_i_stacked,
                  state=self.match_lstm_cell.zero_state(
                      self.batch_size, dtype=tf.float32
                  ),
              )
          else:
              h_r_old, cell_state_old = self.match_lstm_cell(
                  z_i_stacked, state=cell_state_old
              )
  
          final_state_list.append(h_r_old)
          h_r_old = tf.expand_dims(h_r_old, 2)
          stacked_lists = tf.stack(final_state_list, 1)
  
      if not reverse:
          # Mask Output
          mask_mult_lstm_forward = tf.matmul(
              tf.transpose(self.ones_embed, [0, 2, 1]),
              tf.expand_dims(self.para_mask, 1),
          )
  
          self.stacked_lists_forward = tf.multiply(
              tf.transpose(stacked_lists, [0, 2, 1]),
              mask_mult_lstm_forward,
          )
      else:
          # Mask Output
          mask_mult_lstm_reverse = tf.matmul(
              tf.transpose(self.ones_embed, [0, 2, 1]),
              tf.expand_dims(tf.reverse(self.para_mask, axis=[1]), 1),
          )
  
          self.stacked_lists_reverse = tf.reverse(
              tf.multiply(
                  tf.transpose(stacked_lists, [0, 2, 1]),
                  mask_mult_lstm_reverse,
              ),
              axis=[2],
          )
  
file_path: nlp-architect/examples/reading_comprehension/match_lstm_mrc/matchlstm_ansptr.py
imports: from __future__ import division
  from __future__ import print_function
  import re
  from collections import Counter
  import numpy
  import tensorflow
  from nlp_architect.utils.text import SpacyInstance
label_desc: Use image node_id 4 for calling the MatchLSTMAnswerPointer obj's underlying member method code with example usage: obj.unroll_with_attention(reverse) without return types