

'''simple docstring'''



import math

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCamelCase						:  Dict							       =				logging.get_logger(__name__)

_UpperCamelCase						:  List[Any]							       =				{
    "facebook/data2vec-base-960h": "https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json",
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}



class 				_snake_case					(   a_			):
  SCREAMING_SNAKE_CASE			:       List[str]				=     '''data2vec-audio'''

  def __init__(				self      , _SCREAMING_SNAKE_CASE=32      , _SCREAMING_SNAKE_CASE=7_68      , _SCREAMING_SNAKE_CASE=12      , _SCREAMING_SNAKE_CASE=12      , _SCREAMING_SNAKE_CASE=30_72      , _SCREAMING_SNAKE_CASE="gelu"      , _SCREAMING_SNAKE_CASE=0.1      , _SCREAMING_SNAKE_CASE=0.1      , _SCREAMING_SNAKE_CASE=0.1      , _SCREAMING_SNAKE_CASE=0.0      , _SCREAMING_SNAKE_CASE=0.1      , _SCREAMING_SNAKE_CASE=0.1      , _SCREAMING_SNAKE_CASE=0.02      , _SCREAMING_SNAKE_CASE=1e-5      , _SCREAMING_SNAKE_CASE="gelu"      , _SCREAMING_SNAKE_CASE=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)      , _SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)      , _SCREAMING_SNAKE_CASE=(10, 3, 3, 3, 3, 2, 2)      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=16      , _SCREAMING_SNAKE_CASE=19      , _SCREAMING_SNAKE_CASE=5      , _SCREAMING_SNAKE_CASE=0.05      , _SCREAMING_SNAKE_CASE=10      , _SCREAMING_SNAKE_CASE=2      , _SCREAMING_SNAKE_CASE=0.0      , _SCREAMING_SNAKE_CASE=10      , _SCREAMING_SNAKE_CASE=0      , _SCREAMING_SNAKE_CASE="sum"      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=2_56      , _SCREAMING_SNAKE_CASE=(5_12, 5_12, 5_12, 5_12, 15_00)      , _SCREAMING_SNAKE_CASE=(5, 3, 3, 1, 1)      , _SCREAMING_SNAKE_CASE=(1, 2, 3, 1, 1)      , _SCREAMING_SNAKE_CASE=5_12      , _SCREAMING_SNAKE_CASE=0      , _SCREAMING_SNAKE_CASE=1      , _SCREAMING_SNAKE_CASE=2      , _SCREAMING_SNAKE_CASE=False      , _SCREAMING_SNAKE_CASE=3      , _SCREAMING_SNAKE_CASE=2      , _SCREAMING_SNAKE_CASE=3      , _SCREAMING_SNAKE_CASE=None      , **_SCREAMING_SNAKE_CASE      , ):





      '''simple docstring'''

      super().__init__(**_SCREAMING_SNAKE_CASE      , pad_token_id=_SCREAMING_SNAKE_CASE      , bos_token_id=_SCREAMING_SNAKE_CASE      , eos_token_id=_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							hidden_size
      lowerCAmelCase 						=							feat_extract_activation
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							conv_bias
      lowerCAmelCase 						=							num_conv_pos_embeddings
      lowerCAmelCase 						=							num_conv_pos_embedding_groups
      lowerCAmelCase 						=							conv_pos_kernel_size
      lowerCAmelCase 						=							len(self.conv_dim	)
      lowerCAmelCase 						=							num_hidden_layers
      lowerCAmelCase 						=							intermediate_size
      lowerCAmelCase 						=							hidden_act
      lowerCAmelCase 						=							num_attention_heads
      lowerCAmelCase 						=							hidden_dropout
      lowerCAmelCase 						=							attention_dropout
      lowerCAmelCase 						=							activation_dropout
      lowerCAmelCase 						=							feat_proj_dropout
      lowerCAmelCase 						=							final_dropout
      lowerCAmelCase 						=							layerdrop
      lowerCAmelCase 						=							layer_norm_eps
      lowerCAmelCase 						=							initializer_range
      lowerCAmelCase 						=							vocab_size
      lowerCAmelCase 						=							use_weighted_layer_sum

      if (
          (len(self.conv_stride	) != self.num_feat_extract_layers)
          or (len(self.conv_kernel	) != self.num_feat_extract_layers)
          or (len(self.conv_dim	) != self.num_feat_extract_layers)
      ):
          raise ValueError(
              'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
              ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
              F' {len(self.conv_dim	)}`, `len(config.conv_stride) = {len(self.conv_stride	)}`,'
              F' `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'	)

      # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
      lowerCAmelCase 						=							mask_time_prob
      lowerCAmelCase 						=							mask_time_length
      lowerCAmelCase 						=							mask_time_min_masks
      lowerCAmelCase 						=							mask_feature_prob
      lowerCAmelCase 						=							mask_feature_length
      lowerCAmelCase 						=							mask_feature_min_masks

      # ctc loss
      lowerCAmelCase 						=							ctc_loss_reduction
      lowerCAmelCase 						=							ctc_zero_infinity

      # adapter
      lowerCAmelCase 						=							add_adapter
      lowerCAmelCase 						=							adapter_kernel_size
      lowerCAmelCase 						=							adapter_stride
      lowerCAmelCase 						=							num_adapter_layers
      lowerCAmelCase 						=							output_hidden_size or hidden_size

      # SequenceClassification-specific parameter. Feel free to ignore for other classes.
      lowerCAmelCase 						=							classifier_proj_size

      # XVector-specific parameters. Feel free to ignore for other classes.
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							list(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							xvector_output_dim


  @property
  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      return math.prod(self.conv_stride	)








'''simple docstring'''



import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast



@dataclass
class 				_snake_case					(   datasets.BuilderConfig			):
  SCREAMING_SNAKE_CASE			:       Optional[datasets.Features]				=     None



class 				_snake_case					(   datasets.ArrowBasedBuilder			):
  SCREAMING_SNAKE_CASE			:       Tuple				=     PandasConfig

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      return datasets.DatasetInfo(features=self.config.features	)

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      if not self.config.data_files:
          raise ValueError(F'At least one data file must be specified, but got data_files={self.config.data_files}'	)
      lowerCAmelCase 						=							dl_manager.download_and_extract(self.config.data_files	)
      if isinstance(_SCREAMING_SNAKE_CASE      , (str, list, tuple)	):
          lowerCAmelCase 						=							data_files
          if isinstance(_SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):
              lowerCAmelCase 						=							[files]
          # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
          lowerCAmelCase 						=							[dl_manager.iter_files(_SCREAMING_SNAKE_CASE	) for file in files]
          return [datasets.SplitGenerator(name=datasets.Split.TRAIN      , gen_kwargs={'files': files}	)]
      lowerCAmelCase 						=							[]
      for split_name, files in data_files.items():
          if isinstance(_SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):
              lowerCAmelCase 						=							[files]
          # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
          lowerCAmelCase 						=							[dl_manager.iter_files(_SCREAMING_SNAKE_CASE	) for file in files]
          splits.append(datasets.SplitGenerator(name=_SCREAMING_SNAKE_CASE      , gen_kwargs={'files': files}	)	)
      return splits

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      if self.config.features is not None:
          # more expensive cast to support nested features with keys in a different order
          # allows str <-> int/float or str to Audio for example
          lowerCAmelCase 						=							table_cast(_SCREAMING_SNAKE_CASE      , self.config.features.arrow_schema	)
      return pa_table


  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      for i, file in enumerate(itertools.chain.from_iterable(_SCREAMING_SNAKE_CASE	)	):
          with open(_SCREAMING_SNAKE_CASE      , 'rb'	) as f:
              lowerCAmelCase 						=							pa.Table.from_pandas(pd.read_pickle(_SCREAMING_SNAKE_CASE	)	)
              yield i, self._cast_table(_SCREAMING_SNAKE_CASE	)





