class_docstr: Cell for Sequential User Matrix
class_docstr_tok: ["Cell","for","Sequential","User","Matrix"]
docstr: The real operations for SUM cell to process user behaviors.
  
  params:
      inputs: (a batch of) user behaviors at time T
      state:  (a batch of) user states at time T-1
  
  returns:
      state, state:
      - after process the user behavior at time T, returns (a batch of) new user states at time T
      - after process the user behavior at time T, returns (a batch of) new user states at time T
docstr_tok: ["The","real","operations","for","SUM","cell","to","process","user","behaviors",".","params",":","inputs",":","(","a","batch","of",")","user","behaviors","at","time","T","state",":","(","a","batch","of",")","user","states","at","time","T-1","returns",":","state",",","state",":","-","after","process","the","user","behavior","at","time","T",",","returns","(","a","batch","of",")","new","user","states","at","time","T","-","after","process","the","user","behavior","at","time","T",",","returns","(","a","batch","of",")","new","user","states","at","time","T"]
code: def call(self, inputs, state):
      """The real operations for SUM cell to process user behaviors.
  
      params:
          inputs: (a batch of) user behaviors at time T
          state:  (a batch of) user states at time T-1
  
      returns:
          state, state:
          - after process the user behavior at time T, returns (a batch of) new user states at time T
          - after process the user behavior at time T, returns (a batch of) new user states at time T
      """
      _check_rnn_cell_input_dtypes([inputs, state])
  
      h = self._real_units
      s = self._slots + 1
      state, last = state[:, : s * h], state[:, s * h :]
      state = tf.reshape(state, [-1, s, h])
  
      att_logit_mat = tf.matmul(inputs, self.heads, transpose_b=True)
  
      att_weights = tf.nn.softmax(self._beta * att_logit_mat, axis=-1)
      att_weights = tf.expand_dims(att_weights, 2)
  
      h_hat = tf.reduce_sum(
          input_tensor=tf.multiply(
              state[:, : self._slots, :], att_weights
          ),
          axis=1,
      )
      h_hat = (h_hat + state[:, self._slots, :]) / 2
  
      n_a, n_b = tf.nn.l2_normalize(last, 1), tf.nn.l2_normalize(
          inputs, 1
      )
      dist = tf.expand_dims(
          tf.reduce_sum(input_tensor=n_a * n_b, axis=1), 1
      )
      dist = tf.math.pow(self._alpha, dist)
  
      att_weights = att_weights * tf.expand_dims(dist, 1)
  
      reset = tf.sigmoid(
          tf.compat.v1.nn.xw_plus_b(
              tf.concat([inputs, h_hat], axis=-1),
              self._reset_W,
              self._reset_b,
          )
      )
      erase = tf.sigmoid(
          tf.compat.v1.nn.xw_plus_b(
              tf.concat([inputs, h_hat], axis=-1),
              self._erase_W,
              self._erase_b,
          )
      )
      add = tf.tanh(
          tf.compat.v1.nn.xw_plus_b(
              tf.concat([inputs, reset * h_hat], axis=-1),
              self._add_W,
              self._add_b,
          )
      )
  
      start_part01 = state[:, : self._slots, :]
      state01 = start_part01 * (
          tf.ones_like(start_part01)
          - att_weights * tf.expand_dims(erase, 1)
      )
      state01 = state01 + att_weights * tf.expand_dims(
          erase, 1
      ) * tf.expand_dims(add, 1)
      state01 = tf.reshape(
          state01, [-1, self._slots * self._real_units]
      )
  
      start_part02 = state[:, self._slots, :]
      state02 = start_part02 * (
          tf.ones_like(start_part02) - dist * erase
      )
      state02 = state02 + dist * erase * add
      state = tf.concat([state01, state02, inputs], axis=-1)
      return state, state
  
imports: import numpy
  import tensorflow
  from keras.layers.legacy_rnn.rnn_cell_impl import LayerRNNCell
  from tensorflow.python.eager import context
  from tensorflow.python.keras import activations
  from tensorflow.python.keras import initializers
  from tensorflow.python.keras.utils import tf_utils
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.ops import init_ops
  from tensorflow.python.framework import dtypes
  from tensorflow.python.util import nest
label_desc: Use image node_id 6 for calling the SUMCell obj's underlying member method code with example usage: obj.call(inputs, state) and returns: state,  state