class_docstr: Sequential User Matrix Model
  
  :Citation:
  
      Lian, J., Batal, I., Liu, Z., Soni, A., Kang, E. Y., Wang, Y., & Xie, X.,
      "Multi-Interest-Aware User Modeling for Large-Scale Sequential Recommendations", arXiv preprint arXiv:2102.09211, 2021.
docstr: Merge a user's memory states conditioned by a query item.
  
  Params:
      seq_output: A flatten representation of SUM memory states for (a batch of) users
      query: (a batch of) target item candidates
  
  Returns:
      tf.Tensor, tf.Tensor: Merged user representation. Attention weights of each memory channel.
docstr_tok: ["Merge","a","user","'s","memory","states","conditioned","by","a","query","item",".","Params",":","seq_output",":","A","flatten","representation","of","SUM","memory","states","for","(","a","batch","of",")","users","query",":","(","a","batch","of",")","target","item","candidates","Returns",":","tf.Tensor",",","tf.Tensor",":","Merged","user","representation",".","Attention","weights","of","each","memory","channel","."]
code: def _attention_query_by_state(self, seq_output, query):
      """Merge a user's memory states conditioned by a query item.
  
      Params:
          seq_output: A flatten representation of SUM memory states for (a batch of) users
          query: (a batch of) target item candidates
  
      Returns:
          tf.Tensor, tf.Tensor: Merged user representation. Attention weights of each memory channel.
      """
      dim_q = query.shape[-1]
      att_weights = tf.constant(1.0, dtype=tf.float32)
      with tf.compat.v1.variable_scope("query_att"):
          if self.hparams.slots > 1:
              query_att_W = tf.compat.v1.get_variable(
                  name="query_att_W",
                  shape=[self.hidden_size, dim_q],
                  initializer=self.initializer,
              )
  
              # reshape the memory states to (BatchSize, Slots, HiddenSize)
              memory_state = tf.reshape(
                  seq_output, [-1, self.hparams.slots, self.hidden_size]
              )
  
              att_weights = tf.nn.softmax(
                  tf.squeeze(
                      tf.matmul(
                          tf.tensordot(
                              memory_state, query_att_W, axes=1
                          ),
                          tf.expand_dims(query, -1),
                      ),
                      -1,
                  ),
                  -1,
              )
              # merge the memory states, the final shape is (BatchSize, HiddenSize)
              att_res = tf.reduce_sum(
                  input_tensor=memory_state
                  * tf.expand_dims(att_weights, -1),
                  axis=1,
              )
  
          else:
              att_res = seq_output
  
      return att_res, att_weights
  
file_path: recommenders/recommenders/models/deeprec/models/sequential/sum.py
imports: import tensorflow
  from tensorflow.compat.v1.nn import dynamic_rnn
  from recommenders.models.deeprec.models.sequential.sequential_base_model import SequentialBaseModel
  from recommenders.models.deeprec.models.sequential.sum_cells import SUMCell, SUMV2Cell
label_desc: Use image node_id 2 for calling the SUMModel obj's underlying member method code with example usage: obj._attention_query_by_state(seq_output, query) and returns: att_res,  att_weights