class_docstr: This class implements an attentive statistic pooling layer for each channel.
  It returns the concatenated mean and std of the input tensor.
  
  Arguments
  ---------
  channels: int
      The number of input channels.
  attention_channels: int
      The number of attention channels.
  
  Example
  -------
  >>> inp_tensor = torch.rand([8, 120, 64]).transpose(1, 2)
  >>> asp_layer = AttentiveStatisticsPooling(64)
  >>> lengths = torch.rand((8,))
  >>> out_tensor = asp_layer(inp_tensor, lengths).transpose(1, 2)
  >>> out_tensor.shape
  torch.Size([8, 1, 128])
class_docstr_tok: ["This","class","implements","an","attentive","statistic","pooling","layer","for","each","channel",".","It","returns","the","concatenated","mean","and","std","of","the","input","tensor",".","Arguments","--","--","--","--","-","channels",":","int","The","number","of","input","channels",".","attention_channels",":","int","The","number","of","attention","channels",".","Example","--","--","--","-",">",">",">","inp_tensor","=","torch.rand","(","[","8",",","120",",","64","]",")",".transpose","(","1",",","2",")",">",">",">","asp_layer","=","AttentiveStatisticsPooling","(","64",")",">",">",">","lengths","=","torch.rand","(","(","8",",",")",")",">",">",">","out_tensor","=","asp_layer","(","inp_tensor",",","lengths",")",".transpose","(","1",",","2",")",">",">",">","out_tensor.shape","torch.Size","(","[","8",",","1",",","128","]",")"]
code: def __init__(
      self, channels, attention_channels=128, global_context=True
  ):
      super().__init__()
  
      self.eps = 1e-12
      self.global_context = global_context
      if global_context:
          self.tdnn = TDNNBlock(channels * 3, attention_channels, 1, 1)
      else:
          self.tdnn = TDNNBlock(channels, attention_channels, 1, 1)
      self.tanh = nn.Tanh()
      self.conv = Conv1d(
          in_channels=attention_channels,
          out_channels=channels,
          kernel_size=1,
      )
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from speechbrain.dataio.dataio import length_to_mask
  from speechbrain.nnet.CNN import Conv1d
  from speechbrain.nnet.normalization import BatchNorm1d
  from speechbrain.nnet.linear import Linear
label_desc: Use image node_id 1 to create a new AttentiveStatisticsPooling object from inherited base classes: nn with example: obj = AttentiveStatisticsPooling(channels, attention_channels, global_context)