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 inference_mode for reading comprehension
  
  Args:
      session: tensorflow session
      valid: data dictionary for validation set
      vocab_tuple: a tuple containing voacab dictionaries in forward and reverse directions
      num_examples : specify the number of samples to run for inference
      dropout : Float value which is always 1.0 for inference
      dynamic_question_mode : boolean to enable whether or not accept
                              questions from the user(used in the demo mode)
docstr_tok: ["Function","to","run","inference_mode","for","reading","comprehension","Args",":","session",":","tensorflow","session","valid",":","data","dictionary","for","validation","set","vocab_tuple",":","a","tuple","containing","voacab","dictionaries","in","forward","and","reverse","directions","num_examples",":","specify","the","number","of","samples","to","run","for","inference","dropout",":","Float","value","which","is","always","1.0","for","inference","dynamic_question_mode",":","boolean","to","enable","whether","or","not","accept","questions","from","the","user","(","used","in","the","demo","mode",")"]
code: def inference_mode(
      self,
      session,
      valid,
      vocab_tuple,
      num_examples,
      dropout=1.0,
      dynamic_question_mode=False,
      dynamic_usr_question="",
      dynamic_question_index=0,
  ):
      """
      Function to run inference_mode for reading comprehension
  
      Args:
          session: tensorflow session
          valid: data dictionary for validation set
          vocab_tuple: a tuple containing voacab dictionaries in forward and reverse directions
          num_examples : specify the number of samples to run for inference
          dropout : Float value which is always 1.0 for inference
          dynamic_question_mode : boolean to enable whether or not accept
                                  questions from the user(used in the demo mode)
  
      """
      vocab_forward = vocab_tuple[0]
      vocab_reverse = vocab_tuple[1]
  
      for idx in range(num_examples):
          if dynamic_question_mode is True:
              idx = dynamic_question_index
              required_params = self.get_dynamic_feed_params(
                  dynamic_usr_question, vocab_reverse
              )
              question_ids = required_params[0]
              question_length = required_params[1]
              ques_mask = required_params[2]
              test_paragraph = [
                  vocab_forward[ele]
                  for ele in valid[idx][0]
                  if ele != 0
              ]
              para_string = " ".join(map(str, test_paragraph))
          else:
              # Print Paragraph
              print("\n")
              print("Paragraph Number AA:", idx)
              test_paragraph = [
                  vocab_forward[ele].replace(" ", "")
                  for ele in valid[idx][0]
                  if ele != 0
              ]
              para_string = " ".join(map(str, test_paragraph))
              print(para_string)
  
              # Print corresponding Question
              test_question = [
                  vocab_forward[ele].replace(" ", "")
                  for ele in valid[idx][1]
                  if ele != 0
              ]
              ques_string = " ".join(map(str, test_question))
              print("Question:", ques_string)
              question_ids = valid[idx][1]
              question_length = valid[idx][3]
              ques_mask = valid[idx][6]
  
          # Create a feed dictionary
          feed_dict_qa = {
              self.para_ids: np.expand_dims(valid[idx][0], 0),
              self.question_ids: np.expand_dims(question_ids, 0),
              self.para_length: np.expand_dims(valid[idx][2], 0),
              self.question_length: np.expand_dims(question_length, 0),
              self.para_mask: np.expand_dims(valid[idx][5], 0),
              self.ques_mask: np.expand_dims(ques_mask, 0),
              self.dropout: dropout,
          }
  
          # Run session and obtain indices
          predictions = session.run(
              [self.logits_withsf], feed_dict=feed_dict_qa
          )
  
          # Get the start and end indices of the answer
          start_idx, end_idx = self.obtain_indices(
              predictions[0][0], predictions[0][1]
          )
          answer_ind = valid[idx][0][start_idx[0] : end_idx[0] + 1]
  
          # Print answer
          req_ans = [
              vocab_forward[ele].replace(" ", "")
              for ele in answer_ind
              if ele != 0
          ]
          ans_string = " ".join(map(str, req_ans))
          answer = re.sub(r'\s([?.!",])', r"\1", ans_string)
          print("Answer:", answer)
          if dynamic_question_mode is True:
              return {"answer": answer}
  
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 10 for calling the MatchLSTMAnswerPointer obj's underlying member method code with example usage: obj.inference_mode(session, valid, vocab_tuple, num_examples, dropout, dynamic_question_mode, dynamic_usr_question, dynamic_question_index) and returns: dict