
import math

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


__lowerCAmelCase					:			Any			      =		logging.get_logger(__name__)

__lowerCAmelCase					:			Dict			      =		{
    "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 						__lowerCAmelCase	(	lowerCAmelCase_      ):



      """simple docstring"""







      A__	:			int        =    '''data2vec-audio'''




      def __init__(      self		:       str				,       _snake_case		:       List[str]=32				,       _snake_case		:       Optional[Any]=768				,       _snake_case		:       Any=12				,       _snake_case		:       Any=12				,       _snake_case		:       Any=3072				,       _snake_case		:       int="gelu"				,       _snake_case		:       Union[str, Any]=0.1				,       _snake_case		:       int=0.1				,       _snake_case		:       Dict=0.1				,       _snake_case		:       int=0.0				,       _snake_case		:       Dict=0.1				,       _snake_case		:       Optional[int]=0.1				,       _snake_case		:       List[Any]=0.02				,       _snake_case		:       List[Any]=1E-5				,       _snake_case		:       List[str]="gelu"				,       _snake_case		:       Union[str, Any]=(512, 512, 512, 512, 512, 512, 512)				,       _snake_case		:       Optional[Any]=(5, 2, 2, 2, 2, 2, 2)				,       _snake_case		:       str=(10, 3, 3, 3, 3, 2, 2)				,       _snake_case		:       Tuple=False				,       _snake_case		:       Any=16				,       _snake_case		:       List[str]=19				,       _snake_case		:       Optional[int]=5				,       _snake_case		:       Optional[int]=0.05				,       _snake_case		:       Optional[Any]=10				,       _snake_case		:       int=2				,       _snake_case		:       str=0.0				,       _snake_case		:       Optional[Any]=10				,       _snake_case		:       str=0				,       _snake_case		:       Any="sum"				,       _snake_case		:       List[str]=False				,       _snake_case		:       Any=False				,       _snake_case		:       Tuple=256				,       _snake_case		:       Optional[Any]=(512, 512, 512, 512, 1500)				,       _snake_case		:       Tuple=(5, 3, 3, 1, 1)				,       _snake_case		:       Dict=(1, 2, 3, 1, 1)				,       _snake_case		:       Tuple=512				,       _snake_case		:       Dict=0				,       _snake_case		:       List[str]=1				,       _snake_case		:       Dict=2				,       _snake_case		:       Optional[int]=False				,       _snake_case		:       List[Any]=3				,       _snake_case		:       Union[str, Any]=2				,       _snake_case		:       Optional[Any]=3				,       _snake_case		:       Tuple=None				,       **_snake_case		:       List[Any]				,       ):
          super().__init__(**_snake_case				,       pad_token_id=_snake_case				,       bos_token_id=_snake_case				,       eos_token_id=_snake_case				)
          __lowercase		:			List[Any]	    =       hidden_size
          __lowercase		:			Tuple	    =       feat_extract_activation
          __lowercase		:			int	    =       list(_snake_case				)
          __lowercase		:			Any	    =       list(_snake_case				)
          __lowercase		:			Tuple	    =       list(_snake_case				)
          __lowercase		:			Optional[Any]	    =       conv_bias
          __lowercase		:			List[Any]	    =       num_conv_pos_embeddings
          __lowercase		:			int	    =       num_conv_pos_embedding_groups
          __lowercase		:			Optional[Any]	    =       conv_pos_kernel_size
          __lowercase		:			int	    =       len(self.conv_dim				)
          __lowercase		:			str	    =       num_hidden_layers
          __lowercase		:			Dict	    =       intermediate_size
          __lowercase		:			List[Any]	    =       hidden_act
          __lowercase		:			List[Any]	    =       num_attention_heads
          __lowercase		:			Optional[Any]	    =       hidden_dropout
          __lowercase		:			Optional[int]	    =       attention_dropout
          __lowercase		:			Any	    =       activation_dropout
          __lowercase		:			List[Any]	    =       feat_proj_dropout
          __lowercase		:			Dict	    =       final_dropout
          __lowercase		:			int	    =       layerdrop
          __lowercase		:			Tuple	    =       layer_norm_eps
          __lowercase		:			List[Any]	    =       initializer_range
          __lowercase		:			List[str]	    =       vocab_size
          __lowercase		:			Tuple	    =       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
          __lowercase		:			List[Any]	    =       mask_time_prob
          __lowercase		:			List[str]	    =       mask_time_length
          __lowercase		:			Optional[Any]	    =       mask_time_min_masks
          __lowercase		:			Tuple	    =       mask_feature_prob
          __lowercase		:			Dict	    =       mask_feature_length
          __lowercase		:			Dict	    =       mask_feature_min_masks

          # ctc loss
          __lowercase		:			Dict	    =       ctc_loss_reduction
          __lowercase		:			List[Any]	    =       ctc_zero_infinity

          # adapter
          __lowercase		:			Optional[Any]	    =       add_adapter
          __lowercase		:			Optional[Any]	    =       adapter_kernel_size
          __lowercase		:			Dict	    =       adapter_stride
          __lowercase		:			Tuple	    =       num_adapter_layers
          __lowercase		:			Dict	    =       output_hidden_size or hidden_size

          # SequenceClassification-specific parameter. Feel free to ignore for other classes.
          __lowercase		:			str	    =       classifier_proj_size

          # XVector-specific parameters. Feel free to ignore for other classes.
          __lowercase		:			Union[str, Any]	    =       list(_snake_case				)
          __lowercase		:			Optional[int]	    =       list(_snake_case				)
          __lowercase		:			Union[str, Any]	    =       list(_snake_case				)
          __lowercase		:			List[Any]	    =       xvector_output_dim




      @property
      def 		snake_case_			(      self		:       Dict				):
          return math.prod(self.conv_stride				)




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 						__lowerCAmelCase	(	datasets.BuilderConfig      ):



      """simple docstring"""







      A__	:			Optional[datasets.Features]        =    None






class 						__lowerCAmelCase	(	datasets.ArrowBasedBuilder      ):



      """simple docstring"""







      A__	:			List[str]        =    PandasConfig




      def 		snake_case_			(      self		:       int				):
          return datasets.DatasetInfo(features=self.config.features				)




      def 		snake_case_			(      self		:       int				,       _snake_case		:       Optional[int]				):
          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}'				)
          __lowercase		:			Any	    =       dl_manager.download_and_extract(self.config.data_files				)
          if isinstance(_snake_case				,       (str, list, tuple)				):
              __lowercase		:			str	    =       data_files
              if isinstance(_snake_case				,       _snake_case				):
                  __lowercase		:			Any	    =       [files]
              # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
              __lowercase		:			Optional[int]	    =       [dl_manager.iter_files(_snake_case				) for file in files]
              return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,       gen_kwargs={'''files''': files}				)]
          __lowercase		:			str	    =       []
          for split_name, files in data_files.items():
              if isinstance(_snake_case				,       _snake_case				):
                  __lowercase		:			str	    =       [files]
              # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
              __lowercase		:			int	    =       [dl_manager.iter_files(_snake_case				) for file in files]
              splits.append(datasets.SplitGenerator(name=_snake_case				,       gen_kwargs={'''files''': files}				)				)
          return splits




      def 		snake_case_			(      self		:       Optional[int]				,       _snake_case		:       pa.Table				):
          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
              __lowercase		:			List[str]	    =       table_cast(_snake_case				,       self.config.features.arrow_schema				)
          return pa_table




      def 		snake_case_			(      self		:       int				,       _snake_case		:       Union[str, Any]				):
          for i, file in enumerate(itertools.chain.from_iterable(_snake_case				)				):
              with open(_snake_case				,       '''rb'''				) as f:
                  __lowercase		:			Dict	    =       pa.Table.from_pandas(pd.read_pickle(_snake_case				)				)
                  yield i, self._cast_table(_snake_case				)


