class_docstr: Module representing users through running a recurrent neural network
  over the sequence, using the hidden state at each timestep as the
  sequence representation, a'la [2]_
  
  During training, representations for all timesteps of the sequence are
  computed in one go. Loss functions using the outputs will therefore
  be aggregating both across the minibatch and across time in the sequence.
  
  Parameters
  ----------
  
  num_items: int
      Number of items to be represented.
  embedding_dim: int, optional
      Embedding dimension of the embedding layer, and the number of hidden
      units in the LSTM layer.
  item_embedding_layer: an embedding layer, optional
      If supplied, will be used as the item embedding layer
      of the network.
  
  References
  ----------
  
  .. [2] Hidasi, Balazs, et al. "Session-based recommendations with
     recurrent neural networks." arXiv preprint arXiv:1511.06939 (2015).
class_docstr_tok: ["Module","representing","users","through","running","a","recurrent","neural","network","over","the","sequence",",","using","the","hidden","state","at","each","timestep","as","the","sequence","representation",",","a'la","[","2","]","_","During","training",",","representations","for","all","timesteps","of","the","sequence","are","computed","in","one","go",".","Loss","functions","using","the","outputs","will","therefore","be","aggregating","both","across","the","minibatch","and","across","time","in","the","sequence",".","Parameters","--","--","--","--","--","num_items",":","int","Number","of","items","to","be","represented",".","embedding_dim",":","int",",","optional","Embedding","dimension","of","the","embedding","layer",",","and","the","number","of","hidden","units","in","the","LSTM","layer",".","item_embedding_layer",":","an","embedding","layer",",","optional","If","supplied",",","will","be","used","as","the","item","embedding","layer","of","the","network",".","References","--","--","--","--","--","..","[","2","]","Hidasi",",","Balazs",",","et","al",".","``","Session-based","recommendations","with","recurrent","neural","networks",".","''","arXiv","preprint","arXiv:1511.06939","(","2015",")","."]
docstr: Compute user representation from a given sequence.
  
  Returns
  -------
  
  tuple (all_representations, final_representation)
      The first element contains all representations from step
      -1 (no items seen) to t - 1 (all but the last items seen).
      The second element contains the final representation
      at step t (all items seen). This final state can be used
      for prediction or evaluation.
docstr_tok: ["Compute","user","representation","from","a","given","sequence",".","Returns","--","--","--","-","tuple","(","all_representations",",","final_representation",")","The","first","element","contains","all","representations","from","step","-1","(","no","items","seen",")","to","t","-","1","(","all","but","the","last","items","seen",")",".","The","second","element","contains","the","final","representation","at","step","t","(","all","items","seen",")",".","This","final","state","can","be","used","for","prediction","or","evaluation","."]
code: def user_representation(self, item_sequences):
      """
      Compute user representation from a given sequence.
  
      Returns
      -------
  
      tuple (all_representations, final_representation)
          The first element contains all representations from step
          -1 (no items seen) to t - 1 (all but the last items seen).
          The second element contains the final representation
          at step t (all items seen). This final state can be used
          for prediction or evaluation.
      """
  
      # Make the embedding dimension the channel dimension
      sequence_embeddings = self.item_embeddings(
          item_sequences
      ).permute(0, 2, 1)
      # Add a trailing dimension of 1
      sequence_embeddings = sequence_embeddings.unsqueeze(3)
      # Pad it with zeros from left
      sequence_embeddings = F.pad(
          sequence_embeddings, (0, 0, 1, 0)
      ).squeeze(3)
      sequence_embeddings = sequence_embeddings.permute(0, 2, 1)
  
      user_representations, _ = self.lstm(sequence_embeddings)
      user_representations = user_representations.permute(0, 2, 1)
  
      return (
          user_representations[:, :, :-1],
          user_representations[:, :, -1],
      )
  
imports: import torch
  from torch.backends import cudnn
  import torch.nn
  import torch.nn.functional
  from spotlight.layers import ScaledEmbedding, ZeroEmbedding
label_desc: Use image node_id 2 for calling the LSTMNet obj's underlying member method code with example usage: obj.user_representation(item_sequences) and returns: user_representations,  user_representations