class_docstr: End-To-End Memory Network.
class_docstr_tok: ["End-To-End","Memory","Network","."]
docstr: Creates an End-To-End Memory Network for Goal Oriented Dialog
  
  Args:
      cands: Encoded candidate answers
  
      batch_size: The size of the batch.
  
      vocab_size: The size of the vocabulary (should include the nil word). The nil word
      one-hot encoding should be 0.
  
      sentence_size: The max size of a sentence in the data. All sentences should be padded
      to this length. If padding is required it should be done with nil one-hot encoding (0).
  
      memory_size: The max size of the memory. Since Tensorflow currently does not support
      jagged arrays all memories must be padded to this length. If padding is required, the
      extra memories should be
  
      empty memories; memories filled with the nil word ([0, 0, 0, ......, 0]).
  
      embedding_size: The size of the word embedding.
  
      hops: The number of hops. A hop consists of reading and addressing a memory slot.
      Defaults to `3`.
  
      max_grad_norm: Maximum L2 norm clipping value. Defaults to `40.0`.
  
      nonlin: Non-linearity. Defaults to `None`.
  
      initializer: Weight initializer. Defaults to
      `tf.random_normal_initializer(stddev=0.1)`.
  
      optimizer: Optimizer algorithm used for SGD. Defaults to
      `tf.train.AdamOptimizer(learning_rate=1e-2)`.
  
      session: Tensorflow Session the model is run with. Defaults to `tf.Session()`.
  
      name: Name of the End-To-End Memory Network. Defaults to `MemN2N`.
docstr_tok: ["Creates","an","End-To-End","Memory","Network","for","Goal","Oriented","Dialog","Args",":","cands",":","Encoded","candidate","answers","batch_size",":","The","size","of","the","batch",".","vocab_size",":","The","size","of","the","vocabulary","(","should","include","the","nil","word",")",".","The","nil","word","one-hot","encoding","should","be","0.","sentence_size",":","The","max","size","of","a","sentence","in","the","data",".","All","sentences","should","be","padded","to","this","length",".","If","padding","is","required","it","should","be","done","with","nil","one-hot","encoding","(","0",")",".","memory_size",":","The","max","size","of","the","memory",".","Since","Tensorflow","currently","does","not","support","jagged","arrays","all","memories","must","be","padded","to","this","length",".","If","padding","is","required",",","the","extra","memories","should","be","empty","memories",";","memories","filled","with","the","nil","word","(","[","0",",","0",",","0",",","......",",","0","]",")",".","embedding_size",":","The","size","of","the","word","embedding",".","hops",":","The","number","of","hops",".","A","hop","consists","of","reading","and","addressing","a","memory","slot",".","Defaults","to","`","3","`",".","max_grad_norm",":","Maximum","L2","norm","clipping","value",".","Defaults","to","`","40.0","`",".","nonlin",":","Non-linearity",".","Defaults","to","`","None","`",".","initializer",":","Weight","initializer",".","Defaults","to","`","tf.random_normal_initializer","(","stddev=0.1",")","`",".","optimizer",":","Optimizer","algorithm","used","for","SGD",".","Defaults","to","`","tf.train.AdamOptimizer","(","learning_rate=1e-2",")","`",".","session",":","Tensorflow","Session","the","model","is","run","with",".","Defaults","to","`","tf.Session","(",")","`",".","name",":","Name","of","the","End-To-End","Memory","Network",".","Defaults","to","`","MemN2N","`","."]
code: def __init__(
      self,
      batch_size,
      vocab_size,
      sentence_size,
      memory_size,
      embedding_size,
      num_cands,
      max_cand_len,
      hops=3,
      max_grad_norm=40.0,
      nonlin=None,
      initializer=tf.random_normal_initializer(stddev=0.1),
      optimizer=tf.train.AdamOptimizer(
          learning_rate=0.001, epsilon=1e-8
      ),
      session=tf.Session(),
      name="MemN2N_Dialog",
  ):
      """Creates an End-To-End Memory Network for Goal Oriented Dialog
  
      Args:
          cands: Encoded candidate answers
  
          batch_size: The size of the batch.
  
          vocab_size: The size of the vocabulary (should include the nil word). The nil word
          one-hot encoding should be 0.
  
          sentence_size: The max size of a sentence in the data. All sentences should be padded
          to this length. If padding is required it should be done with nil one-hot encoding (0).
  
          memory_size: The max size of the memory. Since Tensorflow currently does not support
          jagged arrays all memories must be padded to this length. If padding is required, the
          extra memories should be
  
          empty memories; memories filled with the nil word ([0, 0, 0, ......, 0]).
  
          embedding_size: The size of the word embedding.
  
          hops: The number of hops. A hop consists of reading and addressing a memory slot.
          Defaults to `3`.
  
          max_grad_norm: Maximum L2 norm clipping value. Defaults to `40.0`.
  
          nonlin: Non-linearity. Defaults to `None`.
  
          initializer: Weight initializer. Defaults to
          `tf.random_normal_initializer(stddev=0.1)`.
  
          optimizer: Optimizer algorithm used for SGD. Defaults to
          `tf.train.AdamOptimizer(learning_rate=1e-2)`.
  
          session: Tensorflow Session the model is run with. Defaults to `tf.Session()`.
  
          name: Name of the End-To-End Memory Network. Defaults to `MemN2N`.
      """
  
      self._batch_size = batch_size
      self._vocab_size = vocab_size
      self._sentence_size = sentence_size
      self._memory_size = memory_size
      self._embedding_size = embedding_size
      self._max_cand_len = max_cand_len
      self._num_cands = num_cands
      self._hops = hops
      self._max_grad_norm = max_grad_norm
      self._nonlin = nonlin
      self._init = initializer
      self._name = name
  
      self._build_inputs()
      self._build_vars()
  
      self._opt = optimizer
  
      # cross entropy
      logits = self._inference(
          self._stories, self._queries
      )  # (batch_size, vocab_size)
      cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
          logits=logits,
          labels=tf.cast(self._answers, tf.float32),
          name="cross_entropy",
      )
      # loss op
      cross_entropy_sum = tf.reduce_sum(
          cross_entropy, name="cross_entropy_sum"
      )
  
      # gradient pipeline
      grads_and_vars = self._opt.compute_gradients(cross_entropy_sum)
      grads_and_vars = [
          (tf.clip_by_norm(g, self._max_grad_norm), v)
          for g, v in grads_and_vars
      ]
      nil_grads_and_vars = []
      for g, v in grads_and_vars:
          if v.name in self._nil_vars:
              nil_grads_and_vars.append((zero_nil_slot(g), v))
          else:
              nil_grads_and_vars.append((g, v))
      train_op = self._opt.apply_gradients(
          nil_grads_and_vars, name="train_op"
      )
  
      # predict ops
      predict_op = tf.argmax(logits, 1, name="predict_op")
      predict_proba_op = tf.nn.softmax(logits, name="predict_proba_op")
      predict_log_proba_op = tf.log(
          predict_proba_op, name="predict_log_proba_op"
      )
  
      # assign ops
      self.loss_op = cross_entropy_sum
      self.predict_op = predict_op
      self.predict_proba_op = predict_proba_op
      self.predict_log_proba_op = predict_log_proba_op
      self.train_op = train_op
  
      init_op = tf.global_variables_initializer()
      self._sess = session
      self._sess.run(init_op)
      self.saver = tf.train.Saver(max_to_keep=1)
  
file_path: nlp-architect/examples/memn2n_dialogue/memn2n_dialogue.py
imports: from __future__ import absolute_import
  from __future__ import division
  import tensorflow
  from six.moves import range
label_desc: Use image node_id 1 to create a new MemN2N_Dialog object from inherited base classes: object with example: obj = MemN2N_Dialog(batch_size, vocab_size, sentence_size, memory_size, embedding_size, num_cands, max_cand_len, hops, max_grad_norm, nonlin, initializer, optimizer, session, name)