





"""simple docstring"""
import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


__UpperCamelCase     :						Union[str, Any]						       =  '''\
    Text data.
    Second line of data.'''

__UpperCamelCase     :						Tuple						       =  '''file'''

@pytest.fixture(scope='session'			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    List[Any]			):
 lowerCAmelCase    				= tmp_path_factory.mktemp('data'			) / (FILE_PATH + '.zstd')
 lowerCAmelCase    				= bytes(_UpperCAmelCase  ,     'utf-8'			)
 with zstd.open(_UpperCAmelCase  ,     'wb'			) as f:
  f.write(_UpperCAmelCase			)
 return path

@pytest.fixture
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    str			):
 with open(os.path.join(tmpfs.local_root_dir  ,     _UpperCAmelCase			)  ,     'w'			) as f:
  f.write(_UpperCAmelCase			)
 return FILE_PATH

@pytest.mark.parametrize('compression_format'  ,     ['gzip', 'xz', 'zstd']			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Optional[Any]  ,     _UpperCAmelCase					:    int  ,     _UpperCAmelCase					:    str  ,     _UpperCAmelCase					:    Tuple  ,     _UpperCAmelCase					:    Any  ,     _UpperCAmelCase					:    List[str]			):
 lowerCAmelCase    				= {'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
 lowerCAmelCase    				= input_paths[compression_format]
 lowerCAmelCase    				= tmp_path / 'cache'
 lowerCAmelCase    				= DownloadConfig(cache_dir=_UpperCAmelCase  ,     extract_compressed_file=_UpperCAmelCase			)
 lowerCAmelCase    				= cached_path(_UpperCAmelCase  ,     download_config=_UpperCAmelCase			)
 with open(_UpperCAmelCase			) as f:
  lowerCAmelCase    				= f.read()
 with open(_UpperCAmelCase			) as f:
  lowerCAmelCase    				= f.read()
 assert extracted_file_content == expected_file_content

@pytest.mark.parametrize('default_extracted'  ,     [True, False]			)
@pytest.mark.parametrize('default_cache_dir'  ,     [True, False]			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Dict  ,     _UpperCAmelCase					:    Optional[Any]  ,     _UpperCAmelCase					:    Any  ,     _UpperCAmelCase					:    Tuple  ,     _UpperCAmelCase					:    str			):
 lowerCAmelCase    				= 'custom_cache'
 lowerCAmelCase    				= 'custom_extracted_dir'
 lowerCAmelCase    				= tmp_path / 'custom_extracted_path'
 if default_extracted:
  lowerCAmelCase    				= ('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
 else:
  monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'  ,     _UpperCAmelCase			)
  monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'  ,     str(_UpperCAmelCase			)			)
  lowerCAmelCase    				= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

 lowerCAmelCase    				= xz_file
 lowerCAmelCase    				= (
     DownloadConfig(extract_compressed_file=_UpperCAmelCase			)
     if default_cache_dir
     else DownloadConfig(cache_dir=tmp_path / custom_cache_dir  ,     extract_compressed_file=_UpperCAmelCase			)
 )
 lowerCAmelCase    				= cached_path(_UpperCAmelCase  ,     download_config=_UpperCAmelCase			)
 assert Path(_UpperCAmelCase			).parent.parts[-2:] == expected

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Union[str, Any]			):
 # absolute path
 lowerCAmelCase    				= str(Path(_UpperCAmelCase			).resolve()			)
 assert cached_path(_UpperCAmelCase			) == text_file
 # relative path
 lowerCAmelCase    				= str(Path(_UpperCAmelCase			).resolve().relative_to(Path(os.getcwd()			)			)			)
 assert cached_path(_UpperCAmelCase			) == text_file

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Optional[Any]			):
 # absolute path
 lowerCAmelCase    				= str(tmp_path.resolve() / '__missing_file__.txt'			)
 with pytest.raises(_UpperCAmelCase			):
  cached_path(_UpperCAmelCase			)
 # relative path
 lowerCAmelCase    				= './__missing_file__.txt'
 with pytest.raises(_UpperCAmelCase			):
  cached_path(_UpperCAmelCase			)

def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    int			):
 lowerCAmelCase    				= get_from_cache(F'tmp://{tmpfs_file}'			)
 with open(_UpperCAmelCase			) as f:
  lowerCAmelCase    				= f.read()
 assert output_file_content == FILE_CONTENT

@patch('datasets.config.HF_DATASETS_OFFLINE'  ,     _UpperCAmelCase			)
def 		_SCREAMING_SNAKE_CASE			():
 with pytest.raises(_UpperCAmelCase			):
  cached_path('https://huggingface.co'			)

@patch('datasets.config.HF_DATASETS_OFFLINE'  ,     _UpperCAmelCase			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Optional[Any]			):
 lowerCAmelCase    				= tmp_path_factory.mktemp('data'			) / 'file.html'
 with pytest.raises(_UpperCAmelCase			):
  http_get('https://huggingface.co'  ,     temp_file=_UpperCAmelCase			)
 with pytest.raises(_UpperCAmelCase			):
  http_head('https://huggingface.co'			)

@patch('datasets.config.HF_DATASETS_OFFLINE'  ,     _UpperCAmelCase			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    Dict			):
 lowerCAmelCase    				= tmp_path_factory.mktemp('data'			) / 'file.html'
 with pytest.raises(_UpperCAmelCase			):
  ftp_get('ftp://huggingface.co'  ,     temp_file=_UpperCAmelCase			)
 with pytest.raises(_UpperCAmelCase			):
  ftp_head('ftp://huggingface.co'			)




@patch('datasets.config.HF_DATASETS_OFFLINE'  ,     _UpperCAmelCase			)
def 		_SCREAMING_SNAKE_CASE			(_UpperCAmelCase					:    List[str]			):
 lowerCAmelCase    				= tmp_path_factory.mktemp('data'			) / 'file.html'
 with pytest.raises(_UpperCAmelCase			):
  fsspec_get('s3://huggingface.co'  ,     temp_file=_UpperCAmelCase			)
 with pytest.raises(_UpperCAmelCase			):
  fsspec_head('s3://huggingface.co'			)












"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase     :						Union[str, Any]						       =  logging.get_logger(__name__)

__UpperCamelCase     :						Tuple						       =  {
    '''bert-base-uncased''': '''https://huggingface.co/bert-base-uncased/resolve/main/config.json''',
    '''bert-large-uncased''': '''https://huggingface.co/bert-large-uncased/resolve/main/config.json''',
    '''bert-base-cased''': '''https://huggingface.co/bert-base-cased/resolve/main/config.json''',
    '''bert-large-cased''': '''https://huggingface.co/bert-large-cased/resolve/main/config.json''',
    '''bert-base-multilingual-uncased''': '''https://huggingface.co/bert-base-multilingual-uncased/resolve/main/config.json''',
    '''bert-base-multilingual-cased''': '''https://huggingface.co/bert-base-multilingual-cased/resolve/main/config.json''',
    '''bert-base-chinese''': '''https://huggingface.co/bert-base-chinese/resolve/main/config.json''',
    '''bert-base-german-cased''': '''https://huggingface.co/bert-base-german-cased/resolve/main/config.json''',
    '''bert-large-uncased-whole-word-masking''': (
        '''https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/config.json'''
    ),
    '''bert-large-cased-whole-word-masking''': (
        '''https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/config.json'''
    ),
    '''bert-large-uncased-whole-word-masking-finetuned-squad''': (
        '''https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json'''
    ),
    '''bert-large-cased-whole-word-masking-finetuned-squad''': (
        '''https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/config.json'''
    ),
    '''bert-base-cased-finetuned-mrpc''': '''https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/config.json''',
    '''bert-base-german-dbmdz-cased''': '''https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/config.json''',
    '''bert-base-german-dbmdz-uncased''': '''https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/config.json''',
    '''cl-tohoku/bert-base-japanese''': '''https://huggingface.co/cl-tohoku/bert-base-japanese/resolve/main/config.json''',
    '''cl-tohoku/bert-base-japanese-whole-word-masking''': (
        '''https://huggingface.co/cl-tohoku/bert-base-japanese-whole-word-masking/resolve/main/config.json'''
    ),
    '''cl-tohoku/bert-base-japanese-char''': (
        '''https://huggingface.co/cl-tohoku/bert-base-japanese-char/resolve/main/config.json'''
    ),
    '''cl-tohoku/bert-base-japanese-char-whole-word-masking''': (
        '''https://huggingface.co/cl-tohoku/bert-base-japanese-char-whole-word-masking/resolve/main/config.json'''
    ),
    '''TurkuNLP/bert-base-finnish-cased-v1''': (
        '''https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/config.json'''
    ),
    '''TurkuNLP/bert-base-finnish-uncased-v1''': (
        '''https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/config.json'''
    ),
    '''wietsedv/bert-base-dutch-cased''': '''https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/config.json''',
    # See all BERT models at https://huggingface.co/models?filter=bert
}







class       a							(   a__  ):
 snake_case__             =       '''bert'''



 def __init__(     self				,       _snake_case=3_05_22				,       _snake_case=7_68				,       _snake_case=12				,       _snake_case=12				,       _snake_case=30_72				,       _snake_case="gelu"				,       _snake_case=0.1				,       _snake_case=0.1				,       _snake_case=5_12				,       _snake_case=2				,       _snake_case=0.02				,       _snake_case=1E-12				,       _snake_case=0				,       _snake_case="absolute"				,       _snake_case=True				,       _snake_case=None				,       **_snake_case				,       ):







  """simple docstring"""






  super().__init__(pad_token_id=_snake_case				,       **_snake_case     )

  lowerCAmelCase    				= vocab_size
  lowerCAmelCase    				= hidden_size
  lowerCAmelCase    				= num_hidden_layers
  lowerCAmelCase    				= num_attention_heads
  lowerCAmelCase    				= hidden_act
  lowerCAmelCase    				= intermediate_size
  lowerCAmelCase    				= hidden_dropout_prob
  lowerCAmelCase    				= attention_probs_dropout_prob
  lowerCAmelCase    				= max_position_embeddings
  lowerCAmelCase    				= type_vocab_size
  lowerCAmelCase    				= initializer_range
  lowerCAmelCase    				= layer_norm_eps
  lowerCAmelCase    				= position_embedding_type
  lowerCAmelCase    				= use_cache
  lowerCAmelCase    				= classifier_dropout







class       a							(   a__  ):



 @property
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  if self.task == "multiple-choice":
   lowerCAmelCase    				= {0: 'batch', 1: 'choice', 2: 'sequence'}
  else:
   lowerCAmelCase    				= {0: 'batch', 1: 'sequence'}
  return OrderedDict(
      [
          ('input_ids', dynamic_axis),
          ('attention_mask', dynamic_axis),
          ('token_type_ids', dynamic_axis),
      ]     )





