class_docstr: Module representing users through stacked causal atrous convolutions ([3]_, [4]_).
  
  To represent a sequence, it runs a 1D convolution over the input sequence,
  from left to right. At each timestep, the output of the convolution is
  the representation of the sequence up to that point. The convolution is causal
  because future states are never part of the convolution's receptive field;
  this is achieved by left-padding the sequence.
  
  In order to increase the receptive field (and the capacity to encode states
  further back in the sequence), one can increase the kernel width, stack
  more layers, or increase the dilation factor.
  Input dimensionality is preserved from layer to layer.
  
  Residual connections can be added between all layers.
  
  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 filters
      in each convolutional layer.
  kernel_width: tuple or int, optional
      The kernel width of the convolutional layers. If tuple, should contain
      the kernel widths for all convolutional layers. If int, it will be
      expanded into a tuple to match the number of layers.
  dilation: tuple or int, optional
      The dilation factor for atrous convolutions. Setting this to a number
      greater than 1 inserts gaps into the convolutional layers, increasing
      their receptive field without increasing the number of parameters.
      If tuple, should contain the dilation factors for all convolutional
      layers. If int, it will be expanded into a tuple to match the number
      of layers.
  num_layers: int, optional
      Number of stacked convolutional layers.
  nonlinearity: string, optional
      One of ('tanh', 'relu'). Denotes the type of non-linearity to apply
      after each convolutional layer.
  residual_connections: boolean, optional
      Whether to use residual connections between convolutional layers.
  item_embedding_layer: an embedding layer, optional
      If supplied, will be used as the item embedding layer
      of the network.
  
  References
  ----------
  
  .. [3] Oord, Aaron van den, et al. "Wavenet: A generative model for raw audio."
     arXiv preprint arXiv:1609.03499 (2016).
  .. [4] Kalchbrenner, Nal, et al. "Neural machine translation in linear time."
     arXiv preprint arXiv:1610.10099 (2016).
class_docstr_tok: ["Module","representing","users","through","stacked","causal","atrous","convolutions","(","[","3","]","_",",","[","4","]","_",")",".","To","represent","a","sequence",",","it","runs","a","1D","convolution","over","the","input","sequence",",","from","left","to","right",".","At","each","timestep",",","the","output","of","the","convolution","is","the","representation","of","the","sequence","up","to","that","point",".","The","convolution","is","causal","because","future","states","are","never","part","of","the","convolution","'s","receptive","field",";","this","is","achieved","by","left-padding","the","sequence",".","In","order","to","increase","the","receptive","field","(","and","the","capacity","to","encode","states","further","back","in","the","sequence",")",",","one","can","increase","the","kernel","width",",","stack","more","layers",",","or","increase","the","dilation","factor",".","Input","dimensionality","is","preserved","from","layer","to","layer",".","Residual","connections","can","be","added","between","all","layers",".","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","filters","in","each","convolutional","layer",".","kernel_width",":","tuple","or","int",",","optional","The","kernel","width","of","the","convolutional","layers",".","If","tuple",",","should","contain","the","kernel","widths","for","all","convolutional","layers",".","If","int",",","it","will","be","expanded","into","a","tuple","to","match","the","number","of","layers",".","dilation",":","tuple","or","int",",","optional","The","dilation","factor","for","atrous","convolutions",".","Setting","this","to","a","number","greater","than","1","inserts","gaps","into","the","convolutional","layers",",","increasing","their","receptive","field","without","increasing","the","number","of","parameters",".","If","tuple",",","should","contain","the","dilation","factors","for","all","convolutional","layers",".","If","int",",","it","will","be","expanded","into","a","tuple","to","match","the","number","of","layers",".","num_layers",":","int",",","optional","Number","of","stacked","convolutional","layers",".","nonlinearity",":","string",",","optional","One","of","(","'tanh","'",",","'relu","'",")",".","Denotes","the","type","of","non-linearity","to","apply","after","each","convolutional","layer",".","residual_connections",":","boolean",",","optional","Whether","to","use","residual","connections","between","convolutional","layers",".","item_embedding_layer",":","an","embedding","layer",",","optional","If","supplied",",","will","be","used","as","the","item","embedding","layer","of","the","network",".","References","--","--","--","--","--","..","[","3","]","Oord",",","Aaron","van","den",",","et","al",".","``","Wavenet",":","A","generative","model","for","raw","audio",".","''","arXiv","preprint","arXiv:1609.03499","(","2016",")",".","..","[","4","]","Kalchbrenner",",","Nal",",","et","al",".","``","Neural","machine","translation","in","linear","time",".","''","arXiv","preprint","arXiv:1610.10099","(","2016",")","."]
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 so that the CNN doesn't have the future
      # of the sequence in its receptive field.
      receptive_field_width = self.kernel_width[0] + (
          self.kernel_width[0] - 1
      ) * (self.dilation[0] - 1)
  
      x = F.pad(sequence_embeddings, (0, 0, receptive_field_width, 0))
      x = self.nonlinearity(self.cnn_layers[0](x))
  
      if self.residual_connections:
          residual = F.pad(sequence_embeddings, (0, 0, 1, 0))
          x = x + residual
  
      for cnn_layer, kernel_width, dilation in zip(
          self.cnn_layers[1:], self.kernel_width[1:], self.dilation[1:]
      ):
          receptive_field_width = kernel_width + (kernel_width - 1) * (
              dilation - 1
          )
          residual = x
          x = F.pad(x, (0, 0, receptive_field_width - 1, 0))
          x = self.nonlinearity(cnn_layer(x))
  
          if self.residual_connections:
              x = x + residual
  
      x = x.squeeze(3)
  
      return x[:, :, :-1], x[:, :, -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 CNNNet obj's underlying member method code with example usage: obj.user_representation(item_sequences) and returns: x,  x