class_docstr: An implementation of multi-layer end-to-end memory network,
  with RNN-like weight tying described in
  (Sukhbaatar et al.) End-To-End Memory Networks .
  
  See :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn` for default
  embedding functions. Customized embedding functions must follow
  the same signature.
  
  Args:
      raw_memory_dim (int): Dimension size of raw memory entries
          (before embedding). For example,
          if a raw memory entry is a word, this is the **vocabulary size**
          (imagine a one-hot representation of word). If a raw memory entry
          is a dense vector, this is the dimension size of the vector.
      input_embed_fn (optional): A callable that embeds raw memory entries
          as inputs.
          This corresponds to the `A` embedding operation in
          (Sukhbaatar et al.)
          If not provided, a default embedding operation is created as
          specified in :attr:`hparams`. See
          :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`
          for details.
      output_embed_fn (optional): A callable that embeds raw memory entries
          as outputs.
          This corresponds to the `C` embedding operation in
          (Sukhbaatar et al.)
          If not provided, a default embedding operation is created as
          specified in :attr:`hparams`. See
          :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`
          for details.
      query_embed_fn (optional): A callable that embeds query.
          This corresponds to the `B` embedding operation in
          (Sukhbaatar et al.). If not provided and "use_B" is True
          in :attr:`hparams`, a default embedding operation is created as
          specified in :attr:`hparams`. See
          :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`
          for details.
          For customized query_embed_fn, note that the function must follow
          the signature of the default embed_fn where `memory_size` must
          be 1.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
docstr: Pass the :attr:`memory` and :attr:`query` through the memory network
  and return the :attr:`logits` after the final matrix.
  
  Only one of :attr:`memory` and :attr:`soft_memory` can be specified.
  They should not be specified at the same time.
  
  Args:
      memory (optional): Memory used in A/C operations. By default, it
          should be an integer tensor of shape
          `[batch_size, memory_size]`,
          containing the ids to embed if provided.
      query (optional): Query vectors as the intial input of the memory
          network.
          If you'd like to apply some transformation (e.g., embedding)
          on it before it's fed into the network, please set `use_B` to
          True and add `query_embed_fn` when constructing this instance.
          If `query_embed_fn` is set to
          :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`,
          it should be of shape `[batch_size]`.
          If `use_B` is not set, it should be of shape
          `[batch_size, memory_dim]`.
      soft_memory (optional): Soft memory used in A/C operations. By
          default, it should be a tensor of shape
          `[batch_size, memory_size, raw_memory_dim]`,
          containing the weights used to mix the embedding vectors.
          If you'd like to apply a matrix multiplication on the memory,
          this option can also be used.
      soft_query (optional): Query vectors as the intial input of the
          memory network.
          If you'd like to apply some transformation (e.g., embedding)
          on it before it's fed into the network, please set `use_B` to
          True and add `query_embed_fn` when constructing this instance.
          Similar to :attr:`soft_memory`, if `query_embed_fn` is set to
          :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`,
          then it must be of shape `[batch_size, raw_memory_dim]`.
          Ignored if `use_B` is not set.
      mode (optional): A tensor taking value in
          :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`, including
          `TRAIN`, `EVAL`, and `PREDICT`. If `None`, dropout is
          controlled by :func:`texar.tf.global_mode`.
docstr_tok: ["Pass","the",":","attr",":","`","memory","`","and",":","attr",":","`","query","`","through","the","memory","network","and","return","the",":","attr",":","`","logits","`","after","the","final","matrix",".","Only","one","of",":","attr",":","`","memory","`","and",":","attr",":","`","soft_memory","`","can","be","specified",".","They","should","not","be","specified","at","the","same","time",".","Args",":","memory","(","optional",")",":","Memory","used","in","A\/C","operations",".","By","default",",","it","should","be","an","integer","tensor","of","shape","`","[","batch_size",",","memory_size","]","`",",","containing","the","ids","to","embed","if","provided",".","query","(","optional",")",":","Query","vectors","as","the","intial","input","of","the","memory","network",".","If","you","'d","like","to","apply","some","transformation","(","e.g.",",","embedding",")","on","it","before","it","'s","fed","into","the","network",",","please","set","`","use_B","`","to","True","and","add","`","query_embed_fn","`","when","constructing","this","instance",".","If","`","query_embed_fn","`","is","set","to",":","meth",":","`","~texar.tf.modules.MemNetBase.get_default_embed_fn","`",",","it","should","be","of","shape","`","[","batch_size","]","`",".","If","`","use_B","`","is","not","set",",","it","should","be","of","shape","`","[","batch_size",",","memory_dim","]","`",".","soft_memory","(","optional",")",":","Soft","memory","used","in","A\/C","operations",".","By","default",",","it","should","be","a","tensor","of","shape","`","[","batch_size",",","memory_size",",","raw_memory_dim","]","`",",","containing","the","weights","used","to","mix","the","embedding","vectors",".","If","you","'d","like","to","apply","a","matrix","multiplication","on","the","memory",",","this","option","can","also","be","used",".","soft_query","(","optional",")",":","Query","vectors","as","the","intial","input","of","the","memory","network",".","If","you","'d","like","to","apply","some","transformation","(","e.g.",",","embedding",")","on","it","before","it","'s","fed","into","the","network",",","please","set","`","use_B","`","to","True","and","add","`","query_embed_fn","`","when","constructing","this","instance",".","Similar","to",":","attr",":","`","soft_memory","`",",","if","`","query_embed_fn","`","is","set","to",":","meth",":","`","~texar.tf.modules.MemNetBase.get_default_embed_fn","`",",","then","it","must","be","of","shape","`","[","batch_size",",","raw_memory_dim","]","`",".","Ignored","if","`","use_B","`","is","not","set",".","mode","(","optional",")",":","A","tensor","taking","value","in",":","tf_main",":","`","tf.estimator.ModeKeys","<","estimator\/ModeKeys",">","`",",","including","`","TRAIN","`",",","`","EVAL","`",",","and","`","PREDICT","`",".","If","`","None","`",",","dropout","is","controlled","by",":","func",":","`","texar.tf.global_mode","`","."]
code: def _build(
      self,
      memory=None,
      query=None,
      soft_memory=None,
      soft_query=None,
      mode=None,
      **kwargs,
  ):
      """Pass the :attr:`memory` and :attr:`query` through the memory network
      and return the :attr:`logits` after the final matrix.
  
      Only one of :attr:`memory` and :attr:`soft_memory` can be specified.
      They should not be specified at the same time.
  
      Args:
          memory (optional): Memory used in A/C operations. By default, it
              should be an integer tensor of shape
              `[batch_size, memory_size]`,
              containing the ids to embed if provided.
          query (optional): Query vectors as the intial input of the memory
              network.
              If you'd like to apply some transformation (e.g., embedding)
              on it before it's fed into the network, please set `use_B` to
              True and add `query_embed_fn` when constructing this instance.
              If `query_embed_fn` is set to
              :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`,
              it should be of shape `[batch_size]`.
              If `use_B` is not set, it should be of shape
              `[batch_size, memory_dim]`.
          soft_memory (optional): Soft memory used in A/C operations. By
              default, it should be a tensor of shape
              `[batch_size, memory_size, raw_memory_dim]`,
              containing the weights used to mix the embedding vectors.
              If you'd like to apply a matrix multiplication on the memory,
              this option can also be used.
          soft_query (optional): Query vectors as the intial input of the
              memory network.
              If you'd like to apply some transformation (e.g., embedding)
              on it before it's fed into the network, please set `use_B` to
              True and add `query_embed_fn` when constructing this instance.
              Similar to :attr:`soft_memory`, if `query_embed_fn` is set to
              :meth:`~texar.tf.modules.MemNetBase.get_default_embed_fn`,
              then it must be of shape `[batch_size, raw_memory_dim]`.
              Ignored if `use_B` is not set.
          mode (optional): A tensor taking value in
              :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`, including
              `TRAIN`, `EVAL`, and `PREDICT`. If `None`, dropout is
              controlled by :func:`texar.tf.global_mode`.
      """
      if self._B is not None:
  
          def _unsqueeze(x):
              return x if x is None else tf.expand_dims(x, 1)
  
          query = tf.squeeze(
              self._B(
                  _unsqueeze(query), _unsqueeze(soft_query), mode=mode
              ),
              1,
          )
      self._u = [query]
      self._m = self._A(memory, soft_memory, mode=mode)
      self._c = self._C(memory, soft_memory, mode=mode)
  
      keep_prob = switch_dropout(
          1 - self.hparams.dropout_rate, mode=mode
      )
      if self.hparams.variational:
          with tf.variable_scope("variational_dropout"):
              noise = tf.random_uniform(tf.shape(self._u[-1]))
              random_tensor = keep_prob + noise
              binary_tensor = tf.floor(random_tensor)
  
          def _variational_dropout(val):
              return tf.math.div(val, keep_prob) * binary_tensor
  
      for _ in range(self._n_hops):
          u_ = self._AC(self._u[-1], self._m, self._c)
          if self._relu_dim == 0:
              pass
          elif self._relu_dim == self._memory_dim:
              u_ = tf.nn.relu(u_)
          elif 0 < self._relu_dim < self._memory_dim:
              linear_part = u_[:, : self._memory_dim - self._relu_dim]
              relu_part = u_[:, self._memory_dim - self._relu_dim :]
              relued_part = tf.nn.relu(relu_part)
              u_ = tf.concat(axis=1, values=[linear_part, relued_part])
          else:
              raise ValueError(
                  "relu_dim = {} is illegal".format(self._relu_dim)
              )
          if self.hparams.variational:
              u_ = _variational_dropout(u_)
          else:
              u_ = tf.nn.dropout(u_, keep_prob)
          self._u.append(u_)
  
      logits = self._W(self._u[-1])
  
      if not self._built:
          self._add_internal_trainable_variables()
          self._built = True
  
      return logits
  
imports: import tensorflow
  from texar.tf.module_base import ModuleBase
  from texar.tf.modules.embedders import WordEmbedder, PositionEmbedder
  from texar.tf.utils.mode import switch_dropout
  from texar.tf.modules.memory.embed_fns import default_memnet_embed_fn_hparams
label_desc: Use image node_id 3 for calling the MemNetRNNLike obj's underlying member method code with example usage: obj._build(memory, query, soft_memory, soft_query, mode) and returns: logits, unknown, unknown