class_docstr: Performs mean and variance normalization of the input tensor.
  
  Arguments
  ---------
  mean_norm : True
       If True, the mean will be normalized.
  std_norm : True
       If True, the standard deviation will be normalized.
  norm_type : str
       It defines how the statistics are computed ('sentence' computes them
       at sentence level, 'batch' at batch level, 'speaker' at speaker
       level, while global computes a single normalization vector for all
       the sentences in the dataset). Speaker and global statistics are
       computed with a moving average approach.
  avg_factor : float
       It can be used to manually set the weighting factor between
       current statistics and accumulated ones.
  
  Example
  -------
  >>> import torch
  >>> norm = InputNormalization()
  >>> inputs = torch.randn([10, 101, 20])
  >>> inp_len = torch.ones([10])
  >>> features = norm(inputs, inp_len)
class_docstr_tok: ["Performs","mean","and","variance","normalization","of","the","input","tensor",".","Arguments","--","--","--","--","-","mean_norm",":","True","If","True",",","the","mean","will","be","normalized",".","std_norm",":","True","If","True",",","the","standard","deviation","will","be","normalized",".","norm_type",":","str","It","defines","how","the","statistics","are","computed","(","'sentence","'","computes","them","at","sentence","level",",","'batch","'","at","batch","level",",","'speaker","'","at","speaker","level",",","while","global","computes","a","single","normalization","vector","for","all","the","sentences","in","the","dataset",")",".","Speaker","and","global","statistics","are","computed","with","a","moving","average","approach",".","avg_factor",":","float","It","can","be","used","to","manually","set","the","weighting","factor","between","current","statistics","and","accumulated","ones",".","Example","--","--","--","-",">",">",">","import","torch",">",">",">","norm","=","InputNormalization","(",")",">",">",">","inputs","=","torch.randn","(","[","10",",","101",",","20","]",")",">",">",">","inp_len","=","torch.ones","(","[","10","]",")",">",">",">","features","=","norm","(","inputs",",","inp_len",")"]
docstr: Returns the tensor with the surrounding context.
  
  Arguments
  ---------
  x : tensor
      A batch of tensors.
  lengths : tensor
      A batch of tensors containing the relative length of each
      sentence (e.g, [0.7, 0.9, 1.0]). It is used to avoid
      computing stats on zero-padded steps.
  spk_ids : tensor containing the ids of each speaker (e.g, [0 10 6]).
      It is used to perform per-speaker normalization when
      norm_type='speaker'.
docstr_tok: ["Returns","the","tensor","with","the","surrounding","context",".","Arguments","--","--","--","--","-","x",":","tensor","A","batch","of","tensors",".","lengths",":","tensor","A","batch","of","tensors","containing","the","relative","length","of","each","sentence","(","e.g",",","[","0.7",",","0.9",",","1.0","]",")",".","It","is","used","to","avoid","computing","stats","on","zero-padded","steps",".","spk_ids",":","tensor","containing","the","ids","of","each","speaker","(","e.g",",","[","0","10","6","]",")",".","It","is","used","to","perform","per-speaker","normalization","when","norm_type='speaker","'","."]
code: def forward(self, x, lengths, spk_ids=torch.tensor([]), epoch=0):
      """Returns the tensor with the surrounding context.
  
      Arguments
      ---------
      x : tensor
          A batch of tensors.
      lengths : tensor
          A batch of tensors containing the relative length of each
          sentence (e.g, [0.7, 0.9, 1.0]). It is used to avoid
          computing stats on zero-padded steps.
      spk_ids : tensor containing the ids of each speaker (e.g, [0 10 6]).
          It is used to perform per-speaker normalization when
          norm_type='speaker'.
      """
      N_batches = x.shape[0]
  
      current_means = []
      current_stds = []
  
      for snt_id in range(N_batches):
          # Avoiding padded time steps
          actual_size = torch.round(lengths[snt_id] * x.shape[1]).int()
  
          # computing statistics
          current_mean, current_std = self._compute_current_stats(
              x[snt_id, 0:actual_size, ...]
          )
  
          current_means.append(current_mean)
          current_stds.append(current_std)
  
          if self.norm_type == "sentence":
              x[snt_id] = (
                  x[snt_id] - current_mean.data
              ) / current_std.data
  
          if self.norm_type == "speaker":
              spk_id = int(spk_ids[snt_id][0])
  
              if self.training:
                  if spk_id not in self.spk_dict_mean:
                      # Initialization of the dictionary
                      self.spk_dict_mean[spk_id] = current_mean
                      self.spk_dict_std[spk_id] = current_std
                      self.spk_dict_count[spk_id] = 1
  
                  else:
                      self.spk_dict_count[spk_id] = (
                          self.spk_dict_count[spk_id] + 1
                      )
  
                      if self.avg_factor is None:
                          self.weight = 1 / self.spk_dict_count[spk_id]
                      else:
                          self.weight = self.avg_factor
  
                      self.spk_dict_mean[spk_id] = (
                          1 - self.weight
                      ) * self.spk_dict_mean[spk_id].to(
                          current_mean
                      ) + self.weight * current_mean
                      self.spk_dict_std[spk_id] = (
                          1 - self.weight
                      ) * self.spk_dict_std[spk_id].to(
                          current_std
                      ) + self.weight * current_std
  
                      self.spk_dict_mean[spk_id].detach()
                      self.spk_dict_std[spk_id].detach()
  
                  speaker_mean = self.spk_dict_mean[spk_id].data
                  speaker_std = self.spk_dict_std[spk_id].data
              else:
                  if spk_id in self.spk_dict_mean:
                      speaker_mean = self.spk_dict_mean[spk_id].data
                      speaker_std = self.spk_dict_std[spk_id].data
                  else:
                      speaker_mean = current_mean.data
                      speaker_std = current_std.data
  
              x[snt_id] = (x[snt_id] - speaker_mean) / speaker_std
  
      if self.norm_type == "batch" or self.norm_type == "global":
          current_mean = torch.mean(torch.stack(current_means), dim=0)
          current_std = torch.mean(torch.stack(current_stds), dim=0)
  
          if self.norm_type == "batch":
              x = (x - current_mean.data) / (current_std.data)
  
          if self.norm_type == "global":
              if self.training:
                  if self.count == 0:
                      self.glob_mean = current_mean
                      self.glob_std = current_std
  
                  elif epoch < self.update_until_epoch:
                      if self.avg_factor is None:
                          self.weight = 1 / (self.count + 1)
                      else:
                          self.weight = self.avg_factor
  
                      self.glob_mean = (
                          1 - self.weight
                      ) * self.glob_mean.to(
                          current_mean
                      ) + self.weight * current_mean
  
                      self.glob_std = (
                          1 - self.weight
                      ) * self.glob_std.to(
                          current_std
                      ) + self.weight * current_std
  
                  self.glob_mean.detach()
                  self.glob_std.detach()
  
                  self.count = self.count + 1
  
              x = (x - self.glob_mean.data.to(x)) / (
                  self.glob_std.data.to(x)
              )
  
      return x
  
imports: import math
  import torch
  import logging
  from speechbrain.utils.checkpoints import mark_as_saver, mark_as_loader, mark_as_transfer, register_checkpoint_hooks
  from speechbrain.dataio.dataio import length_to_mask
label_desc: Use image node_id 2 for calling the InputNormalization obj's underlying member method code with example usage: obj.forward(x, lengths, spk_ids, epoch) and returns: x