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: Write to the memory based on a combination of similarity and least used.
  
  Based on arXiv:1607.00036v2 [cs.LG].
  
  Args:
    x: a tensor in the shape of [batch_size, length, depth].
    access_logits: the logits for accessing the memory.
  Returns:
    the update op.
docstr_tok: ["Write","to","the","memory","based","on","a","combination","of","similarity","and","least","used",".","Based","on","arXiv:1607.00036v2","[","cs.LG","]",".","Args",":","x",":","a","tensor","in","the","shape","of","[","batch_size",",","length",",","depth","]",".","access_logits",":","the","logits","for","accessing","the","memory",".","Returns",":","the","update","op","."]
code: def write(self, x, access_logits):
      """Write to the memory based on a combination of similarity and least used.
  
      Based on arXiv:1607.00036v2 [cs.LG].
  
      Args:
        x: a tensor in the shape of [batch_size, length, depth].
        access_logits: the logits for accessing the memory.
      Returns:
        the update op.
      """
      gamma = tf.layers.dense(x, 1, activation=tf.sigmoid, name="gamma")
      write_logits = access_logits - gamma * tf.expand_dims(
          self.mean_logits, 1
      )
      candidate_value = tf.layers.dense(
          x,
          self.val_depth,
          activation=tf.nn.relu,
          name="candidate_value",
      )
      erase_gates = tf.layers.dense(
          x, self.memory_size, activation=tf.nn.sigmoid, name="erase"
      )
      write_weights = tf.nn.softmax(write_logits)
      erase_weights = tf.expand_dims(1 - erase_gates * write_weights, 3)
      erase = tf.multiply(
          erase_weights, tf.expand_dims(self.mem_vals, 1)
      )
      addition = tf.multiply(
          tf.expand_dims(write_weights, 3),
          tf.expand_dims(candidate_value, 2),
      )
      update_value_op = self.mem_vals.assign(
          tf.reduce_mean(erase + addition, axis=1)
      )
      with tf.control_dependencies([update_value_op]):
          write_op = self.mean_logits.assign(
              self.mean_logits * 0.1
              + tf.reduce_mean(write_logits * 0.9, axis=1)
          )
          return write_op
  
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 5 for calling the TransformerMemory obj's underlying member method code with example usage: obj.write(x, access_logits) and returns: write_op