



'''simple docstring'''




import csv
import json
import os

import datasets


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
a  :     List[str]       =       """\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""

# TODO: Add description of the dataset here
# You can copy an official description
a  :     Union[str, Any]       =       """\
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
"""

# TODO: Add a link to an official homepage for the dataset here
a  :     Optional[int]       =       """"""

# TODO: Add the licence for the dataset here if you can find it
a  :     int       =       """"""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
a  :     List[str]       =       {
    """first_domain""": """https://huggingface.co/great-new-dataset-first_domain.zip""",
    """second_domain""": """https://huggingface.co/great-new-dataset-second_domain.zip""",
}

class      UpperCamelCase_					(				datasets.GeneratorBasedBuilder     ):
	lowercase		=					datasets.Version('1.1.0'     )

	# This is an example of a dataset with multiple configurations.
	# If you don't want/need to define several sub-sets in your dataset,
	# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

	# If you need to make complex sub-parts in the datasets with configurable options
	# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
	# BUILDER_CONFIG_CLASS = MyBuilderConfig

	# You will be able to load one or the other configurations in the following list with
	# data = datasets.load_dataset('my_dataset', 'first_domain')
	# data = datasets.load_dataset('my_dataset', 'second_domain')
	lowercase		=					[
	    datasets.BuilderConfig(name='first_domain' ,	version=__SCREAMING_SNAKE_CASE ,	description='This part of my dataset covers a first domain'     ),
	    datasets.BuilderConfig(name='second_domain' ,	version=__SCREAMING_SNAKE_CASE ,	description='This part of my dataset covers a second domain'     ),
	]

	lowercase		=					"first_domain"  # It's not mandatory to have a default configuration. Just use one if it make sense.





	def 					_lowercase(    self       )     ->     Tuple:
								# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
								if self.config.name == "first_domain":  # This is the name of the configuration selected in BUILDER_CONFIGS above
															UpperCAmelCase	:						int					=						datasets.Features(
															    {
															        """sentence""": datasets.Value("""string"""       ),
															        """option1""": datasets.Value("""string"""       ),
															        """answer""": datasets.Value("""string"""       )
															        # These are the features of your dataset like images, labels ...
															    }       )
								else:  # This is an example to show how to have different features for "first_domain" and "second_domain"
															UpperCAmelCase	:						Dict					=						datasets.Features(
															    {
															        """sentence""": datasets.Value("""string"""       ),
															        """option2""": datasets.Value("""string"""       ),
															        """second_domain_answer""": datasets.Value("""string"""       )
															        # These are the features of your dataset like images, labels ...
															    }       )
								return datasets.DatasetInfo(
								    # This is the description that will appear on the datasets page.
								    description=_DESCRIPTION						,						features=__UpperCAmelCase						,						homepage=_HOMEPAGE						,						license=_LICENSE						,						citation=_CITATION						,						)





	def 					_lowercase(    self						,						A       )     ->     int:
								UpperCAmelCase	:						Union[str, Any]					=						_URLS[self.config.name]
								UpperCAmelCase	:						Any					=						dl_manager.download_and_extract(__UpperCAmelCase       )
								return [
								    datasets.SplitGenerator(
								        name=datasets.Split.TRAIN						,						gen_kwargs={
								            """filepath""": os.path.join(__UpperCAmelCase						,						"""train.jsonl"""       ),
								            """split""": """train""",
								        }						,						),
								    datasets.SplitGenerator(
								        name=datasets.Split.VALIDATION						,						gen_kwargs={
								            """filepath""": os.path.join(__UpperCAmelCase						,						"""dev.jsonl"""       ),
								            """split""": """dev""",
								        }						,						),
								    datasets.SplitGenerator(
								        name=datasets.Split.TEST						,						gen_kwargs={
								            """filepath""": os.path.join(__UpperCAmelCase						,						"""test.jsonl"""       ),
								            """split""": """test"""
								        }						,						),
								]






	def 					_lowercase(    self						,						A						,						A       )     ->     int:
								# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
								# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
								with open(__UpperCAmelCase						,						encoding="""utf-8"""       ) as f:
															for key, row in enumerate(__UpperCAmelCase       ):
																						UpperCAmelCase	:						Tuple					=						json.loads(__UpperCAmelCase       )
																						if self.config.name == "first_domain":
																													# Yields examples as (key, example) tuples
																													yield key, {
																													    "sentence": data["sentence"],
																													    "option1": data["option1"],
																													    "answer": "" if split == "test" else data["answer"],
																													}
																						else:
																													yield key, {
																													    "sentence": data["sentence"],
																													    "option2": data["option2"],
																													    "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
																													}






'''simple docstring'''
from transformers import (
    DPRContextEncoderTokenizer,
    DPRContextEncoderTokenizerFast,
    DPRQuestionEncoderTokenizer,
    DPRQuestionEncoderTokenizerFast,
    DPRReaderOutput,
    DPRReaderTokenizer,
    DPRReaderTokenizerFast,
)
from transformers.testing_utils import require_tokenizers, slow
from transformers.tokenization_utils_base import BatchEncoding

from ..bert.test_tokenization_bert import BertTokenizationTest



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRContextEncoderTokenizer
		_SCREAMING_SNAKE_CASE       :     Optional[int]       =      DPRContextEncoderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      True



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     str       =      DPRQuestionEncoderTokenizer
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRQuestionEncoderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      True



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRReaderTokenizer
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      DPRReaderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Dict       =      True





		@slow
		def 				__A							(  self					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.tokenizer_class.from_pretrained("""bert-base-uncased"""					)

					__UpperCAmelCase :   int    					=  tokenizer.encode("""question sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[Any]    					=  tokenizer.encode("""title sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Any    					=  tokenizer.encode("""text sequence """ * 4			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Tuple    					=  [[101] + text_a + [102] + text_a + [102] + text_a]
					__UpperCAmelCase :   Optional[int]    					=  BatchEncoding({"""input_ids""": input_ids}					)

					__UpperCAmelCase :   str    					=  [[0] * len(input_ids[0]					)]
					__UpperCAmelCase :   str    					=  [[0] * len(input_ids[0]					)]
					__UpperCAmelCase :   Optional[int]    					=  [0]
					__UpperCAmelCase :   List[str]    					=  DPRReaderOutput(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

					__UpperCAmelCase					,	__UpperCAmelCase :   Any    					=  8, 9
					__UpperCAmelCase :   Optional[int]    					=  10
					__UpperCAmelCase :   int    					=  10
					__UpperCAmelCase :   str    					=  tokenizer.decode_best_spans(__UpperCAmelCase			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].start_index			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].end_index			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].doc_id			,							0					)





		@slow
		def 				__A							(  self					)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   Any    					=  self.tokenizer_class.from_pretrained("""bert-base-uncased"""					)

					__UpperCAmelCase :   List[Any]    					=  tokenizer.encode("""question sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   List[str]    					=  tokenizer.encode("""title sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Union[str, Any]    					=  tokenizer.encode("""text sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[int]    					=  [101] + text_a + [102] + text_a + [102] + text_a
					__UpperCAmelCase :   int    					=  tokenizer(questions=["""question sequence"""]			,							titles=["""title sequence"""]			,							texts=["""text sequence"""]					)
					self.assertIn("""input_ids"""			,							__UpperCAmelCase					)
					self.assertIn("""attention_mask"""			,							__UpperCAmelCase					)
					self.assertListEqual(encoded_input["""input_ids"""][0]			,							__UpperCAmelCase					)




