class_docstr: Implements the Memory module.
  
  Based on Neural Turing Machines: arXiv:1410.5401 [cs.NE]
class_docstr_tok: ["Implements","the","Memory","module",".","Based","on","Neural","Turing","Machines",":","arXiv:1410.5401","[","cs.NE","]"]
docstr: Read from the memory.
  
  An external component can use the results via a simple MLP,
  e.g., fn(x W_x + retrieved_mem W_m).
  
  Args:
    x: a tensor in the shape of [batch_size, length, depth].
  Returns:
    access_logits: the logits for accessing the memory in shape of
        [batch_size, length, memory_size].
    retrieved_mem: the retrieved results in the shape of
        [batch_size, length, val_depth].
docstr_tok: ["Read","from","the","memory",".","An","external","component","can","use","the","results","via","a","simple","MLP",",","e.g.",",","fn","(","x","W_x","+","retrieved_mem","W_m",")",".","Args",":","x",":","a","tensor","in","the","shape","of","[","batch_size",",","length",",","depth","]",".","Returns",":","access_logits",":","the","logits","for","accessing","the","memory","in","shape","of","[","batch_size",",","length",",","memory_size","]",".","retrieved_mem",":","the","retrieved","results","in","the","shape","of","[","batch_size",",","length",",","val_depth","]","."]
code: def read(self, x):
      """Read from the memory.
  
      An external component can use the results via a simple MLP,
      e.g., fn(x W_x + retrieved_mem W_m).
  
      Args:
        x: a tensor in the shape of [batch_size, length, depth].
      Returns:
        access_logits: the logits for accessing the memory in shape of
            [batch_size, length, memory_size].
        retrieved_mem: the retrieved results in the shape of
            [batch_size, length, val_depth].
      """
      access_logits = self._address_content(x)
      weights = tf.nn.softmax(access_logits)
      retrieved_mem = tf.reduce_sum(
          tf.multiply(
              tf.expand_dims(weights, 3),
              tf.expand_dims(self.mem_vals, axis=1),
          ),
          axis=2,
      )
      return access_logits, retrieved_mem
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_layers
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling the TransformerMemory obj's underlying member method code with example usage: obj.read(x) and returns: access_logits,  retrieved_mem