"""simple docstring"""




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


_a   :	Dict 					=     logging.get_logger(__name__)

_a   :	List[Any] 					=     {
    'google/realm-cc-news-pretrained-embedder': (
        'https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-encoder': (
        'https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-scorer': (
        'https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-openqa': (
        'https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json'
    ),
    'google/realm-orqa-nq-openqa': 'https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json',
    'google/realm-orqa-nq-reader': 'https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json',
    'google/realm-orqa-wq-openqa': 'https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json',
    'google/realm-orqa-wq-reader': 'https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json',
    # See all REALM models at https://huggingface.co/models?filter=realm
}
class 		__A							(				SCREAMING_SNAKE_CASE_	):
     _UpperCamelCase							:    Optional[int]	      =	"realm"






     def __init__(	self       ,  a__=30522       ,  a__=768       ,  a__=128       ,  a__=12       ,  a__=12       ,  a__=8       ,  a__=3072       ,  a__="gelu_new"       ,  a__=0.1       ,  a__=0.1       ,  a__=512       ,  a__=2       ,  a__=0.0_2       ,  a__=1e-12       ,  a__=256       ,  a__=10       ,  a__=1e-3       ,  a__=5       ,  a__=320       ,  a__=13353718       ,  a__=5000       ,  a__=1       ,  a__=0       ,  a__=2       ,  **a__       ,  ):
       super().__init__(pad_token_id=a__       ,  bos_token_id=a__       ,  eos_token_id=a__       ,  **a__						)

       # Common config
       _lowerCAmelCase		: Dict						    =  vocab_size
       _lowerCAmelCase		: Dict						    =  max_position_embeddings
       _lowerCAmelCase		: List[Any]						    =  hidden_size
       _lowerCAmelCase		: int						    =  retriever_proj_size
       _lowerCAmelCase		: List[Any]						    =  num_hidden_layers
       _lowerCAmelCase		: Any						    =  num_attention_heads
       _lowerCAmelCase		: Union[str, Any]						    =  num_candidates
       _lowerCAmelCase		: List[str]						    =  intermediate_size
       _lowerCAmelCase		: List[str]						    =  hidden_act
       _lowerCAmelCase		: Optional[Any]						    =  hidden_dropout_prob
       _lowerCAmelCase		: Dict						    =  attention_probs_dropout_prob
       _lowerCAmelCase		: Optional[Any]						    =  initializer_range
       _lowerCAmelCase		: Any						    =  type_vocab_size
       _lowerCAmelCase		: Any						    =  layer_norm_eps

       # Reader config
       _lowerCAmelCase		: Any						    =  span_hidden_size
       _lowerCAmelCase		: List[Any]						    =  max_span_width
       _lowerCAmelCase		: Any						    =  reader_layer_norm_eps
       _lowerCAmelCase		: Optional[int]						    =  reader_beam_size
       _lowerCAmelCase		: Union[str, Any]						    =  reader_seq_len

       # Retrieval config
       _lowerCAmelCase		: List[Any]						    =  num_block_records
       _lowerCAmelCase		: Dict						    =  searcher_beam_size





"""simple docstring"""




import unittest

import numpy as np

from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
from transformers.pipelines import AudioClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torchaudio,
    slow,
)

from .test_pipelines_common import ANY
@is_pipeline_test
class 		__A							(				unittest.TestCase	):
     _UpperCamelCase							:    str	      =	MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
     _UpperCamelCase							:    Any	      =	TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING






     def 					__A						(	self       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: List[Any]						    =  AudioClassificationPipeline(model=a__       ,  feature_extractor=a__						)

       # test with a raw waveform
       _lowerCAmelCase		: Optional[int]						    =  np.zeros((34000,)						)
       _lowerCAmelCase		: Optional[Any]						    =  np.zeros((14000,)						)
       return audio_classifier, [audioa, audio]






     def 					__A						(	self       ,  a__       ,  a__						):
       _lowerCAmelCase    ,			_lowerCAmelCase		: List[Any]						    =  examples
       _lowerCAmelCase		: List[Any]						    =  audio_classifier(a__						)
       # by default a model is initialized with num_labels=2
       self.assertEqual(
           a__       ,  [
               {"""score""": ANY(a__						), """label""": ANY(a__						)},
               {"""score""": ANY(a__						), """label""": ANY(a__						)},
           ]       ,  )
       _lowerCAmelCase		: Tuple						    =  audio_classifier(a__       ,  top_k=1						)
       self.assertEqual(
           a__       ,  [
               {"""score""": ANY(a__						), """label""": ANY(a__						)},
           ]       ,  )

       self.run_torchaudio(a__						)






     @require_torchaudio
     def 					__A						(	self       ,  a__						):
       import datasets

       # test with a local file
       _lowerCAmelCase		: int						    =  datasets.load_dataset("""hf-internal-testing/librispeech_asr_dummy"""       ,  """clean"""       ,  split="""validation"""						)
       _lowerCAmelCase		: List[Any]						    =  dataset[0]["""audio"""]["""array"""]
       _lowerCAmelCase		: str						    =  audio_classifier(a__						)
       self.assertEqual(
           a__       ,  [
               {"""score""": ANY(a__						), """label""": ANY(a__						)},
               {"""score""": ANY(a__						), """label""": ANY(a__						)},
           ]       ,  )






     @require_torch
     def 					__A						(	self						):
       _lowerCAmelCase		: int						    =  """anton-l/wav2vec2-random-tiny-classifier"""

       _lowerCAmelCase		: Optional[Any]						    =  pipeline("""audio-classification"""       ,  model=a__						)

       _lowerCAmelCase		: Any						    =  np.ones((8000,)						)
       _lowerCAmelCase		: List[str]						    =  audio_classifier(a__       ,  top_k=4						)

       _lowerCAmelCase		: List[str]						    =  [
           {"""score""": 0.0_8_4_2, """label""": """no"""},
           {"""score""": 0.0_8_3_8, """label""": """up"""},
           {"""score""": 0.0_8_3_7, """label""": """go"""},
           {"""score""": 0.0_8_3_4, """label""": """right"""},
       ]
       _lowerCAmelCase		: str						    =  [
           {"""score""": 0.0_8_4_5, """label""": """stop"""},
           {"""score""": 0.0_8_4_4, """label""": """on"""},
           {"""score""": 0.0_8_4_1, """label""": """right"""},
           {"""score""": 0.0_8_3_4, """label""": """left"""},
       ]
       self.assertIn(nested_simplify(a__       ,  decimals=4						)       ,  [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]						)

       _lowerCAmelCase		: int						    =  {"""array""": np.ones((8000,)						), """sampling_rate""": audio_classifier.feature_extractor.sampling_rate}
       _lowerCAmelCase		: int						    =  audio_classifier(a__       ,  top_k=4						)
       self.assertIn(nested_simplify(a__       ,  decimals=4						)       ,  [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]						)






     @require_torch
     @slow
     def 					__A						(	self						):
       import datasets

       _lowerCAmelCase		: Optional[Any]						    =  """superb/wav2vec2-base-superb-ks"""

       _lowerCAmelCase		: List[str]						    =  pipeline("""audio-classification"""       ,  model=a__						)
       _lowerCAmelCase		: str						    =  datasets.load_dataset("""anton-l/superb_dummy"""       ,  """ks"""       ,  split="""test"""						)

       _lowerCAmelCase		: Optional[Any]						    =  np.array(dataset[3]["""speech"""]       ,  dtype=np.floataa						)
       _lowerCAmelCase		: List[str]						    =  audio_classifier(a__       ,  top_k=4						)
       self.assertEqual(
           nested_simplify(a__       ,  decimals=3						)       ,  [
               {"""score""": 0.9_8_1, """label""": """go"""},
               {"""score""": 0.0_0_7, """label""": """up"""},
               {"""score""": 0.0_0_6, """label""": """_unknown_"""},
               {"""score""": 0.0_0_1, """label""": """down"""},
           ]       ,  )






     @require_tf
     @unittest.skip("""Audio classification is not implemented for TF"""						)
     def 					__A						(	self						):
       pass




