import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     ):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	10
    __UpperCamelCase  :List[Any]    						=	datasets.Features(
        {
            '''tokens''': datasets.Sequence(datasets.Value('''string'''			)			),
            '''labels''': datasets.Sequence(datasets.ClassLabel(names=['''negative''', '''positive''']			)			),
            '''answers''': datasets.Sequence(
                {
                    '''text''': datasets.Value('''string'''			),
                    '''answer_start''': datasets.Value('''int32'''			),
                }			),
            '''id''': datasets.Value('''int64'''			),
        }			)
    __UpperCamelCase  :Optional[int]    						=	datasets.Dataset.from_dict(
        {
            '''tokens''': [['''foo'''] * 5] * n,
            '''labels''': [[1] * 5] * n,
            '''answers''': [{'''answer_start''': [97], '''text''': ['''1976''']}] * 10,
            '''id''': list(range(SCREAMING_SNAKE_CASE			)			),
        }						,    features=SCREAMING_SNAKE_CASE						,    )
    return dataset



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''file.arrow'''			)
    dataset.map(cache_file_name=SCREAMING_SNAKE_CASE			)
    return filename


# FILE_CONTENT + files


__lowercase											=      '''\
    Text data.
    Second line of data.'''



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :List[Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt'''
    __UpperCamelCase  :List[str]    						=	FILE_CONTENT
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return filename



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import bza

    __UpperCamelCase  :int    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.bz2'''
    __UpperCamelCase  :Tuple    						=	bytes(SCREAMING_SNAKE_CASE						,    '''utf-8'''			)
    with bza.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import gzip

    __UpperCamelCase  :Optional[Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''file.txt.gz'''			)
    __UpperCamelCase  :int    						=	bytes(SCREAMING_SNAKE_CASE						,    '''utf-8'''			)
    with gzip.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if datasets.config.LZ4_AVAILABLE:
        import lza.frame

        __UpperCamelCase  :Optional[int]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.lz4'''
        __UpperCamelCase  :int    						=	bytes(SCREAMING_SNAKE_CASE						,    '''utf-8'''			)
        with lza.frame.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
            f.write(SCREAMING_SNAKE_CASE			)
        return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if datasets.config.PY7ZR_AVAILABLE:
        import pyazr

        __UpperCamelCase  :List[Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.7z'''
        with pyazr.SevenZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as archive:
            archive.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import tarfile

    __UpperCamelCase  :Any    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.tar'''
    with tarfile.TarFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.add(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import lzma

    __UpperCamelCase  :List[str]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.xz'''
    __UpperCamelCase  :Union[str, Any]    						=	bytes(SCREAMING_SNAKE_CASE						,    '''utf-8'''			)
    with lzma.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import zipfile

    __UpperCamelCase  :List[str]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if datasets.config.ZSTANDARD_AVAILABLE:
        import zstandard as zstd

        __UpperCamelCase  :str    						=	tmp_path_factory.mktemp('''data'''			) / '''file.txt.zst'''
        __UpperCamelCase  :Optional[int]    						=	bytes(SCREAMING_SNAKE_CASE						,    '''utf-8'''			)
        with zstd.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
            f.write(SCREAMING_SNAKE_CASE			)
        return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''file.xml'''
    __UpperCamelCase  :Optional[int]    						=	textwrap.dedent(
        '''\
    <?xml version="1.0" encoding="UTF-8" ?>
    <tmx version="1.4">
      <header segtype="sentence" srclang="ca" />
      <body>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>
          <tuv xml:lang="en"><seg>Content 1</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>
          <tuv xml:lang="en"><seg>Content 2</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>
          <tuv xml:lang="en"><seg>Content 3</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>
          <tuv xml:lang="en"><seg>Content 4</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>
          <tuv xml:lang="en"><seg>Content 5</seg></tuv>
        </tu>
      </body>
    </tmx>'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return filename


__lowercase											=      [
    {'''col_1''': '''0''', '''col_2''': 0, '''col_3''': 0.0},
    {'''col_1''': '''1''', '''col_2''': 1, '''col_3''': 1.0},
    {'''col_1''': '''2''', '''col_2''': 2, '''col_3''': 2.0},
    {'''col_1''': '''3''', '''col_2''': 3, '''col_3''': 3.0},
]
__lowercase											=      [
    {'''col_1''': '''4''', '''col_2''': 4, '''col_3''': 4.0},
    {'''col_1''': '''5''', '''col_2''': 5, '''col_3''': 5.0},
]
__lowercase											=      {
    '''col_1''': ['''0''', '''1''', '''2''', '''3'''],
    '''col_2''': [0, 1, 2, 3],
    '''col_3''': [0.0, 1.0, 2.0, 3.0],
}

__lowercase											=      [
    {'''col_3''': 0.0, '''col_1''': '''0''', '''col_2''': 0},
    {'''col_3''': 1.0, '''col_1''': '''1''', '''col_2''': 1},
]

__lowercase											=      [
    {'''col_1''': '''s0''', '''col_2''': 0, '''col_3''': 0.0},
    {'''col_1''': '''s1''', '''col_2''': 1, '''col_3''': 1.0},
    {'''col_1''': '''s2''', '''col_2''': 2, '''col_3''': 2.0},
    {'''col_1''': '''s3''', '''col_2''': 3, '''col_3''': 3.0},
]



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     ):
    '''simple docstring'''







    return DATA_DICT_OF_LISTS



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	datasets.Dataset.from_dict(SCREAMING_SNAKE_CASE			)
    __UpperCamelCase  :Dict    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.arrow'''			)
    dataset.map(cache_file_name=SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :List[str]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.sqlite'''			)
    with contextlib.closing(sqlitea.connect(SCREAMING_SNAKE_CASE			)			) as con:
        __UpperCamelCase  :Dict    						=	con.cursor()
        cur.execute('''CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'''			)
        for item in DATA:
            cur.execute('''INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'''						,    tuple(item.values()			)			)
        con.commit()
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.csv'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''						,    newline=''''''			) as f:
        __UpperCamelCase  :List[str]    						=	csv.DictWriter(SCREAMING_SNAKE_CASE						,    fieldnames=['''col_1''', '''col_2''', '''col_3''']			)
        writer.writeheader()
        for item in DATA:
            writer.writerow(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Dict    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset2.csv'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''						,    newline=''''''			) as f:
        __UpperCamelCase  :Any    						=	csv.DictWriter(SCREAMING_SNAKE_CASE						,    fieldnames=['''col_1''', '''col_2''', '''col_3''']			)
        writer.writeheader()
        for item in DATA:
            writer.writerow(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import bza

    __UpperCamelCase  :Dict    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.csv.bz2'''
    with open(SCREAMING_SNAKE_CASE						,    '''rb'''			) as f:
        __UpperCamelCase  :Tuple    						=	f.read()
    # data = bytes(FILE_CONTENT, "utf-8")
    with bza.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :List[Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.csv.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Dict    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.csv.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(csv_path.replace('''.csv'''						,    '''.CSV'''			)			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(csva_path.replace('''.csv'''						,    '''.CSV'''			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Tuple    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset_with_dir.csv.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.parquet'''			)
    __UpperCamelCase  :Optional[Any]    						=	pa.schema(
        {
            '''col_1''': pa.string(),
            '''col_2''': pa.intaa(),
            '''col_3''': pa.floataa(),
        }			)
    with open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as f:
        __UpperCamelCase  :int    						=	pq.ParquetWriter(SCREAMING_SNAKE_CASE						,    schema=SCREAMING_SNAKE_CASE			)
        __UpperCamelCase  :int    						=	pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(SCREAMING_SNAKE_CASE			)			)] for k in DATA[0]}						,    schema=SCREAMING_SNAKE_CASE			)
        writer.write_table(SCREAMING_SNAKE_CASE			)
        writer.close()
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.json'''			)
    __UpperCamelCase  :str    						=	{'''data''': DATA}
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        json.dump(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :int    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.json'''			)
    __UpperCamelCase  :int    						=	{'''data''': DATA_DICT_OF_LISTS}
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        json.dump(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Any    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.jsonl'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in DATA:
            f.write(json.dumps(SCREAMING_SNAKE_CASE			) + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset2.jsonl'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in DATA:
            f.write(json.dumps(SCREAMING_SNAKE_CASE			) + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :int    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset_312.jsonl'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in DATA_312:
            f.write(json.dumps(SCREAMING_SNAKE_CASE			) + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset-str.jsonl'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in DATA_STR:
            f.write(json.dumps(SCREAMING_SNAKE_CASE			) + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import gzip

    __UpperCamelCase  :Tuple    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.txt.gz'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''rb'''			) as orig_file:
        with gzip.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as zipped_file:
            zipped_file.writelines(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    import gzip

    __UpperCamelCase  :Dict    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.jsonl.gz'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''rb'''			) as orig_file:
        with gzip.open(SCREAMING_SNAKE_CASE						,    '''wb'''			) as zipped_file:
            zipped_file.writelines(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.jsonl.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset_nested.jsonl.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''nested'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset_with_dir.jsonl.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :List[str]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.jsonl.tar'''
    with tarfile.TarFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.add(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        f.add(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Tuple    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset_nested.jsonl.tar'''
    with tarfile.TarFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.add(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''nested'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[Any]    						=	['''0''', '''1''', '''2''', '''3''']
    __UpperCamelCase  :str    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset.txt'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in data:
            f.write(item + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Tuple    						=	['''0''', '''1''', '''2''', '''3''']
    __UpperCamelCase  :List[Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset2.txt'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in data:
            f.write(item + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[int]    						=	['''0''', '''1''', '''2''', '''3''']
    __UpperCamelCase  :List[str]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.abc'''
    with open(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        for item in data:
            f.write(item + '''\n'''			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :int    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.text.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset_with_dir.text.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.join('''main_dir'''						,    os.path.basename(SCREAMING_SNAKE_CASE			)			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :int    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.ext.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename('''unsupported.ext'''			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename('''unsupported_2.ext'''			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	'''\n'''.join(['''First''', '''Second\u2029with Unicode new line''', '''Third''']			)
    __UpperCamelCase  :Optional[Any]    						=	str(tmp_path_factory.mktemp('''data'''			) / '''dataset_with_unicode_new_lines.txt'''			)
    with open(SCREAMING_SNAKE_CASE						,    '''w'''						,    encoding='''utf-8'''			) as f:
        f.write(SCREAMING_SNAKE_CASE			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     ):
    '''simple docstring'''







    return os.path.join('''tests'''						,    '''features'''						,    '''data'''						,    '''test_image_rgb.jpg'''			)



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     ):
    '''simple docstring'''







    return os.path.join('''tests'''						,    '''features'''						,    '''data'''						,    '''test_audio_44100.wav'''			)



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Union[str, Any]    						=	tmp_path_factory.mktemp('''data'''			) / '''dataset.img.zip'''
    with zipfile.ZipFile(SCREAMING_SNAKE_CASE						,    '''w'''			) as f:
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			)			)
        f.write(SCREAMING_SNAKE_CASE						,    arcname=os.path.basename(SCREAMING_SNAKE_CASE			).replace('''.jpg'''						,    '''2.jpg'''			)			)
    return path



@pytest.fixture(scope='''session'''			)
def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Optional[int]    						=	tmp_path_factory.mktemp('''data_dir'''			)

    (data_dir / "subdir").mkdir()
    with open(data_dir / '''subdir''' / '''train.txt'''						,    '''w'''			) as f:
        f.write('''foo\n''' * 10			)
    with open(data_dir / '''subdir''' / '''test.txt'''						,    '''w'''			) as f:
        f.write('''bar\n''' * 10			)
    # hidden file
    with open(data_dir / '''subdir''' / '''.test.txt'''						,    '''w'''			) as f:
        f.write('''bar\n''' * 10			)

    # hidden directory
    (data_dir / ".subdir").mkdir()
    with open(data_dir / '''.subdir''' / '''train.txt'''						,    '''w'''			) as f:
        f.write('''foo\n''' * 10			)
    with open(data_dir / '''.subdir''' / '''test.txt'''						,    '''w'''			) as f:
        f.write('''bar\n''' * 10			)

    return data_dir






import functools
import operator

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


__lowercase											=      logging.get_logger(__name__)

__lowercase											=      {
    '''microsoft/unispeech-large-1500h-cv''': (
        '''https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'''
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}


class 			lowerCamelCase_  (     UpperCAmelCase_				):






    '''simple docstring'''






    a__			:		Dict      			=   """unispeech"""







    def __init__(			self				,				__lowercase=32				,				__lowercase=768				,				__lowercase=12				,				__lowercase=12				,				__lowercase=3_072				,				__lowercase="gelu"				,				__lowercase=0.1				,				__lowercase=0.1				,				__lowercase=0.1				,				__lowercase=0.0				,				__lowercase=0.0				,				__lowercase=0.1				,				__lowercase=0.1				,				__lowercase=0.02				,				__lowercase=1E-5				,				__lowercase="group"				,				__lowercase="gelu"				,				__lowercase=(512, 512, 512, 512, 512, 512, 512)				,				__lowercase=(5, 2, 2, 2, 2, 2, 2)				,				__lowercase=(10, 3, 3, 3, 3, 2, 2)				,				__lowercase=False				,				__lowercase=128				,				__lowercase=16				,				__lowercase=False				,				__lowercase=True				,				__lowercase=0.05				,				__lowercase=10				,				__lowercase=2				,				__lowercase=0.0				,				__lowercase=10				,				__lowercase=0				,				__lowercase=320				,				__lowercase=2				,				__lowercase=0.1				,				__lowercase=100				,				__lowercase=256				,				__lowercase=256				,				__lowercase=0.1				,				__lowercase="mean"				,				__lowercase=False				,				__lowercase=False				,				__lowercase=256				,				__lowercase=80				,				__lowercase=0				,				__lowercase=1				,				__lowercase=2				,				__lowercase=0.5				,				**__lowercase				,				) ->			Optional[int]:
        super().__init__(**__lowercase				,				pad_token_id=__lowercase				,				bos_token_id=__lowercase				,				eos_token_id=__lowercase)
        __UpperCamelCase  :str    						=	hidden_size
        __UpperCamelCase  :List[str]    						=	feat_extract_norm
        __UpperCamelCase  :str    						=	feat_extract_activation
        __UpperCamelCase  :str    						=	list(__lowercase)
        __UpperCamelCase  :List[Any]    						=	list(__lowercase)
        __UpperCamelCase  :List[Any]    						=	list(__lowercase)
        __UpperCamelCase  :Any    						=	conv_bias
        __UpperCamelCase  :List[Any]    						=	num_conv_pos_embeddings
        __UpperCamelCase  :Tuple    						=	num_conv_pos_embedding_groups
        __UpperCamelCase  :Optional[int]    						=	len(self.conv_dim)
        __UpperCamelCase  :Optional[int]    						=	num_hidden_layers
        __UpperCamelCase  :Union[str, Any]    						=	intermediate_size
        __UpperCamelCase  :Tuple    						=	hidden_act
        __UpperCamelCase  :Optional[int]    						=	num_attention_heads
        __UpperCamelCase  :Any    						=	hidden_dropout
        __UpperCamelCase  :List[str]    						=	attention_dropout
        __UpperCamelCase  :int    						=	activation_dropout
        __UpperCamelCase  :int    						=	feat_proj_dropout
        __UpperCamelCase  :Any    						=	final_dropout
        __UpperCamelCase  :Optional[Any]    						=	layerdrop
        __UpperCamelCase  :Any    						=	layer_norm_eps
        __UpperCamelCase  :List[str]    						=	initializer_range
        __UpperCamelCase  :Tuple    						=	num_ctc_classes
        __UpperCamelCase  :Union[str, Any]    						=	vocab_size
        __UpperCamelCase  :List[Any]    						=	do_stable_layer_norm
        __UpperCamelCase  :Dict    						=	use_weighted_layer_sum
        __UpperCamelCase  :str    						=	classifier_proj_size

        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
        __UpperCamelCase  :List[Any]    						=	apply_spec_augment
        __UpperCamelCase  :Optional[int]    						=	mask_time_prob
        __UpperCamelCase  :int    						=	mask_time_length
        __UpperCamelCase  :Any    						=	mask_time_min_masks
        __UpperCamelCase  :Any    						=	mask_feature_prob
        __UpperCamelCase  :str    						=	mask_feature_length
        __UpperCamelCase  :Tuple    						=	mask_feature_min_masks

        # parameters for pretraining with codevector quantized representations
        __UpperCamelCase  :Optional[Any]    						=	num_codevectors_per_group
        __UpperCamelCase  :Dict    						=	num_codevector_groups
        __UpperCamelCase  :Optional[int]    						=	contrastive_logits_temperature
        __UpperCamelCase  :Union[str, Any]    						=	feat_quantizer_dropout
        __UpperCamelCase  :List[str]    						=	num_negatives
        __UpperCamelCase  :Union[str, Any]    						=	codevector_dim
        __UpperCamelCase  :int    						=	proj_codevector_dim
        __UpperCamelCase  :Tuple    						=	diversity_loss_weight

        # ctc loss
        __UpperCamelCase  :List[Any]    						=	ctc_loss_reduction
        __UpperCamelCase  :int    						=	ctc_zero_infinity

        # pretraining loss
        __UpperCamelCase  :Optional[Any]    						=	replace_prob







    @property
    def     UpperCamelCase__     (			self) ->			Dict:
        return functools.reduce(operator.mul				,				self.conv_stride				,				1)





