class_docstr: A representation that models users as mixtures-of-tastes.
  
  This is accomplished via an LSTM with a layer on top that
  projects the last hidden state taste vectors and
  taste attention vectors that match items with the taste
  vectors that are best for evaluating them.
  
  For a full description of the model, see [5]_.
  
  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.
  num_mixtures: int, optional
      Number of mixture components (distinct user tastes) that
      the network should model.
  item_embedding_layer: an embedding layer, optional
      If supplied, will be used as the item embedding layer
      of the network.
  
  References
  ----------
  
  .. [5] Kula, Maciej. "Mixture-of-tastes Models for Representing
     Users with Diverse Interests" https://github.com/maciejkula/mixture (2017)
class_docstr_tok: ["A","representation","that","models","users","as","mixtures-of-tastes",".","This","is","accomplished","via","an","LSTM","with","a","layer","on","top","that","projects","the","last","hidden","state","taste","vectors","and","taste","attention","vectors","that","match","items","with","the","taste","vectors","that","are","best","for","evaluating","them",".","For","a","full","description","of","the","model",",","see","[","5","]","_.","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",".","num_mixtures",":","int",",","optional","Number","of","mixture","components","(","distinct","user","tastes",")","that","the","network","should","model",".","item_embedding_layer",":","an","embedding","layer",",","optional","If","supplied",",","will","be","used","as","the","item","embedding","layer","of","the","network",".","References","--","--","--","--","--","..","[","5","]","Kula",",","Maciej",".","``","Mixture-of-tastes","Models","for","Representing","Users","with","Diverse","Interests","''","https",":","\/\/github.com\/maciejkula\/mixture","(","2017",")"]
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.
      """
  
      batch_size, sequence_length = item_sequences.size()
  
      # 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
      sequence_embeddings = sequence_embeddings.permute(0, 2, 1)
  
      user_representations, _ = self.lstm(sequence_embeddings)
      user_representations = user_representations.permute(0, 2, 1)
      user_representations = self.projection(user_representations)
      user_representations = user_representations.view(
          batch_size,
          self.num_mixtures * 2,
          self.embedding_dim,
          sequence_length + 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 MixtureLSTMNet obj's underlying member method code with example usage: obj.user_representation(item_sequences) and returns: user_representations,  user_representations