class_docstr: Constructs a Pop2Piano feature extractor.
  
  This feature extractor inherits from [`~feature_extraction_sequence_utils.SequenceFeatureExtractor`] which contains
  most of the main methods. Users should refer to this superclass for more information regarding those methods.
  
  This class extracts rhythm and preprocesses the audio before it is passed to the model. First the audio is passed
  to `RhythmExtractor2013` algorithm which extracts the beat_times, beat positions and estimates their confidence as
  well as tempo in bpm, then beat_times is interpolated and to get beatsteps. Later we calculate
  extrapolated_beatsteps from it to be used in tokenizer. On the other hand audio is resampled to self.sampling_rate
  and preprocessed and then log mel spectogram is computed from that to be used in our transformer model.
  
  Args:
      sampling_rate (`int`, *optional*, defaults to 22050):
          Target Sampling rate of audio signal. It's the sampling rate that we forward to the model.
      padding_value (`int`, *optional*, defaults to 0):
          Padding value used to pad the audio. Should correspond to silences.
      window_size (`int`, *optional*, defaults to 4096):
          Length of the window in samples to which the Fourier transform is applied.
      hop_length (`int`, *optional*, defaults to 1024):
          Step size between each window of the waveform, in samples.
      min_frequency (`float`, *optional*, defaults to 10.0):
          Lowest frequency that will be used in the log-mel spectrogram.
      feature_size (`int`, *optional*, defaults to 512):
          The feature dimension of the extracted features.
      num_bars (`int`, *optional*, defaults to 2):
          Determines interval between each sequence.
class_docstr_tok: ["Constructs","a","Pop2Piano","feature","extractor",".","This","feature","extractor","inherits","from","[","`","~feature_extraction_sequence_utils.SequenceFeatureExtractor","`","]","which","contains","most","of","the","main","methods",".","Users","should","refer","to","this","superclass","for","more","information","regarding","those","methods",".","This","class","extracts","rhythm","and","preprocesses","the","audio","before","it","is","passed","to","the","model",".","First","the","audio","is","passed","to","`","RhythmExtractor2013","`","algorithm","which","extracts","the","beat_times",",","beat","positions","and","estimates","their","confidence","as","well","as","tempo","in","bpm",",","then","beat_times","is","interpolated","and","to","get","beatsteps",".","Later","we","calculate","extrapolated_beatsteps","from","it","to","be","used","in","tokenizer",".","On","the","other","hand","audio","is","resampled","to","self.sampling_rate","and","preprocessed","and","then","log","mel","spectogram","is","computed","from","that","to","be","used","in","our","transformer","model",".","Args",":","sampling_rate","(","`","int","`",",","*","optional","*",",","defaults","to","22050",")",":","Target","Sampling","rate","of","audio","signal",".","It","'s","the","sampling","rate","that","we","forward","to","the","model",".","padding_value","(","`","int","`",",","*","optional","*",",","defaults","to","0",")",":","Padding","value","used","to","pad","the","audio",".","Should","correspond","to","silences",".","window_size","(","`","int","`",",","*","optional","*",",","defaults","to","4096",")",":","Length","of","the","window","in","samples","to","which","the","Fourier","transform","is","applied",".","hop_length","(","`","int","`",",","*","optional","*",",","defaults","to","1024",")",":","Step","size","between","each","window","of","the","waveform",",","in","samples",".","min_frequency","(","`","float","`",",","*","optional","*",",","defaults","to","10.0",")",":","Lowest","frequency","that","will","be","used","in","the","log-mel","spectrogram",".","feature_size","(","`","int","`",",","*","optional","*",",","defaults","to","512",")",":","The","feature","dimension","of","the","extracted","features",".","num_bars","(","`","int","`",",","*","optional","*",",","defaults","to","2",")",":","Determines","interval","between","each","sequence","."]
docstr: Pads the inputs to same length and returns attention_mask.
  
  Args:
      inputs (`BatchFeature`):
          Processed audio features.
      is_batched (`bool`):
          Whether inputs are batched or not.
      return_attention_mask (`bool`):
          Whether to return attention mask or not.
      return_tensors (`str` or [`~utils.TensorType`], *optional*):
          If set, will return tensors instead of list of python integers. Acceptable values are:
          - `'pt'`: Return PyTorch `torch.Tensor` objects.
          - `'np'`: Return Numpy `np.ndarray` objects.
          If nothing is specified, it will return list of `np.ndarray` arrays.
  Return:
      `BatchFeature` with attention_mask, attention_mask_beatsteps and attention_mask_extrapolated_beatstep added
      to it:
      - **attention_mask** numpy.ndarray of shape `(batch_size, max_input_features_seq_length)` --
          Example :
              1, 1, 1, 0, 0 (audio 1, also here it is padded to max length of 5 thats why there are 2 zeros at
              the end indicating they are padded)
  
              0, 0, 0, 0, 0 (zero pad to seperate audio 1 and 2)
  
              1, 1, 1, 1, 1 (audio 2)
  
              0, 0, 0, 0, 0 (zero pad to seperate audio 2 and 3)
  
              1, 1, 1, 1, 1 (audio 3)
      - **attention_mask_beatsteps** numpy.ndarray of shape `(batch_size, max_beatsteps_seq_length)`
      - **attention_mask_extrapolated_beatstep** numpy.ndarray of shape `(batch_size,
        max_extrapolated_beatstep_seq_length)`
docstr_tok: ["Pads","the","inputs","to","same","length","and","returns","attention_mask",".","Args",":","inputs","(","`","BatchFeature","`",")",":","Processed","audio","features",".","is_batched","(","`","bool","`",")",":","Whether","inputs","are","batched","or","not",".","return_attention_mask","(","`","bool","`",")",":","Whether","to","return","attention","mask","or","not",".","return_tensors","(","`","str","`","or","[","`","~utils.TensorType","`","]",",","*","optional","*",")",":","If","set",",","will","return","tensors","instead","of","list","of","python","integers",".","Acceptable","values","are",":","-","`","'pt","'","`",":","Return","PyTorch","`","torch.Tensor","`","objects",".","-","`","'np","'","`",":","Return","Numpy","`","np.ndarray","`","objects",".","If","nothing","is","specified",",","it","will","return","list","of","`","np.ndarray","`","arrays",".","Return",":","`","BatchFeature","`","with","attention_mask",",","attention_mask_beatsteps","and","attention_mask_extrapolated_beatstep","added","to","it",":","-","*","*","attention_mask","*","*","numpy.ndarray","of","shape","`","(","batch_size",",","max_input_features_seq_length",")","`","--","Example",":","1",",","1",",","1",",","0",",","0","(","audio","1",",","also","here","it","is","padded","to","max","length","of","5","thats","why","there","are","2","zeros","at","the","end","indicating","they","are","padded",")","0",",","0",",","0",",","0",",","0","(","zero","pad","to","seperate","audio","1","and","2",")","1",",","1",",","1",",","1",",","1","(","audio","2",")","0",",","0",",","0",",","0",",","0","(","zero","pad","to","seperate","audio","2","and","3",")","1",",","1",",","1",",","1",",","1","(","audio","3",")","-","*","*","attention_mask_beatsteps","*","*","numpy.ndarray","of","shape","`","(","batch_size",",","max_beatsteps_seq_length",")","`","-","*","*","attention_mask_extrapolated_beatstep","*","*","numpy.ndarray","of","shape","`","(","batch_size",",","max_extrapolated_beatstep_seq_length",")","`"]
code: def pad(
      self,
      inputs: BatchFeature,
      is_batched: bool,
      return_attention_mask: bool,
      return_tensors: Optional[Union[str, TensorType]] = None,
  ):
      """
      Pads the inputs to same length and returns attention_mask.
  
      Args:
          inputs (`BatchFeature`):
              Processed audio features.
          is_batched (`bool`):
              Whether inputs are batched or not.
          return_attention_mask (`bool`):
              Whether to return attention mask or not.
          return_tensors (`str` or [`~utils.TensorType`], *optional*):
              If set, will return tensors instead of list of python integers. Acceptable values are:
              - `'pt'`: Return PyTorch `torch.Tensor` objects.
              - `'np'`: Return Numpy `np.ndarray` objects.
              If nothing is specified, it will return list of `np.ndarray` arrays.
      Return:
          `BatchFeature` with attention_mask, attention_mask_beatsteps and attention_mask_extrapolated_beatstep added
          to it:
          - **attention_mask** numpy.ndarray of shape `(batch_size, max_input_features_seq_length)` --
              Example :
                  1, 1, 1, 0, 0 (audio 1, also here it is padded to max length of 5 thats why there are 2 zeros at
                  the end indicating they are padded)
  
                  0, 0, 0, 0, 0 (zero pad to seperate audio 1 and 2)
  
                  1, 1, 1, 1, 1 (audio 2)
  
                  0, 0, 0, 0, 0 (zero pad to seperate audio 2 and 3)
  
                  1, 1, 1, 1, 1 (audio 3)
          - **attention_mask_beatsteps** numpy.ndarray of shape `(batch_size, max_beatsteps_seq_length)`
          - **attention_mask_extrapolated_beatstep** numpy.ndarray of shape `(batch_size,
            max_extrapolated_beatstep_seq_length)`
      """
  
      processed_features_dict = {}
      for feature_name, feature_value in inputs.items():
          if feature_name == "input_features":
              padded_feature_values, attention_mask = self._pad(
                  feature_value, add_zero_line=True
              )
              processed_features_dict[
                  feature_name
              ] = padded_feature_values
              if return_attention_mask:
                  processed_features_dict[
                      "attention_mask"
                  ] = attention_mask
          else:
              padded_feature_values, attention_mask = self._pad(
                  feature_value, add_zero_line=False
              )
              processed_features_dict[
                  feature_name
              ] = padded_feature_values
              if return_attention_mask:
                  processed_features_dict[
                      f"attention_mask_{feature_name}"
                  ] = attention_mask
  
      # If we are processing only one example, we should remove the zero array line since we don't need it to
      # seperate examples from each other.
      if not is_batched and not return_attention_mask:
          processed_features_dict[
              "input_features"
          ] = processed_features_dict["input_features"][:-1, ...]
  
      outputs = BatchFeature(
          processed_features_dict, tensor_type=return_tensors
      )
  
      return outputs
  
file_path: transformers/src/transformers/models/pop2piano/feature_extraction_pop2piano.py
imports: import warnings
  from typing import List, Optional, Union
  import numpy
  import numpy
  from ...audio_utils import mel_filter_bank, spectrogram
  from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
  from ...feature_extraction_utils import BatchFeature
  from ...utils import TensorType, is_essentia_available, is_librosa_available, is_scipy_available, logging, requires_backends
label_desc: Use image node_id 7 for calling the Pop2PianoFeatureExtractor obj's underlying member method code with example usage: obj.pad(inputs, is_batched, return_attention_mask, return_tensors) and returns: outputs