class_docstr: End-To-End Memory Network.
class_docstr_tok: ["End-To-End","Memory","Network","."]
code: def _inference(self, stories, queries):
      with tf.variable_scope(self._name):
          q_emb = tf.nn.embedding_lookup(self.LUT_A, queries)
          u_0 = tf.reduce_sum(q_emb, 1)
          u = [u_0]
  
          for _ in range(self._hops):
              m_emb_A = tf.nn.embedding_lookup(self.LUT_A, stories)
              m_A = tf.reduce_sum(m_emb_A, 2)
  
              # hack to get around no reduce_dot
              u_temp = tf.transpose(
                  tf.expand_dims(u[-1], -1), [0, 2, 1]
              )
              dotted = tf.reduce_sum(m_A * u_temp, 2)
  
              # Calculate probabilities
              probs = tf.nn.softmax(dotted)
  
              probs_temp = tf.transpose(
                  tf.expand_dims(probs, -1), [0, 2, 1]
              )
  
              # Reuse A for the output memory encoding
              c_temp = tf.transpose(m_A, [0, 2, 1])
              o_k = tf.reduce_sum(c_temp * probs_temp, 2)
  
              # Project hidden state, and add update
              u_k = tf.matmul(u[-1], self.R_proj) + o_k
  
              # nonlinearity
              if self._nonlin:
                  u_k = self._nonlin(u_k)
  
              u.append(u_k)
  
          cands_emb = tf.nn.embedding_lookup(self.LUT_W, self._cands)
          cands_emb_sum = tf.reduce_sum(cands_emb, 2)
  
          logits = tf.reshape(
              tf.matmul(
                  tf.expand_dims(u_k, 1),
                  tf.transpose(cands_emb_sum, [0, 2, 1]),
              ),
              (-1, cands_emb_sum.shape[1]),
          )
  
          return logits
  
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 4 for calling the MemN2N_Dialog obj's underlying member method code with example usage: obj._inference(stories, queries) and returns: logits