

'''simple docstring'''



import logging
import os
from dataclasses import dataclass
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from transformers import (
    BartTokenizer,
    BartTokenizerFast,
    DataProcessor,
    PreTrainedTokenizer,
    RobertaTokenizer,
    RobertaTokenizerFast,
    XLMRobertaTokenizer,
    is_tf_available,
    is_torch_available,
)


__snake_case			:     Dict										=      logging.getLogger(__name__)



@dataclass(frozen=lowercase_						)
class lowerCamelCase			:



			'''simple docstring'''






			__snake_case        =	42
			__snake_case        =	42
			__snake_case        =	None
			__snake_case        =	None
			__snake_case        =	None



@dataclass(frozen=lowercase_						)
class lowerCamelCase			:



			'''simple docstring'''






			__snake_case        =	42
			__snake_case        =	None
			__snake_case        =	None
			__snake_case        =	None
			__snake_case        =	None


if is_torch_available():
		import torch
		from torch.utils.data import Dataset



		class lowerCamelCase			(  lowercase_						):



					'''simple docstring'''






					__snake_case        =	42


					def __init__(				self	:						int		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						PreTrainedTokenizer		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						Optional[int] = None		,      lowerCAmelCase_	:						str=False		,      lowerCAmelCase_	:						bool = False		,      )      ->		Optional[int]:





											'''simple docstring'''
											A__					:       Dict     =hans_processors[task]()

											A__					:       List[str]     =os.path.join(
											    lowerCAmelCase_		,      """cached_{}_{}_{}_{}""".format(
											        """dev""" if evaluate else """train"""		,      tokenizer.__class__.__name__		,      str(lowerCAmelCase_			)		,      lowerCAmelCase_		,      )		,      )
											A__					:       Tuple     =processor.get_labels()
											if tokenizer.__class__ in (
											    RobertaTokenizer,
											    RobertaTokenizerFast,
											    XLMRobertaTokenizer,
											    BartTokenizer,
											    BartTokenizerFast,
											):
																	# HACK(label indices are swapped in RoBERTa pretrained model)
																	A__   ,						A__					:       Tuple     =label_list[2], label_list[1]
											A__					:       Tuple     =label_list

											# Make sure only the first process in distributed training processes the dataset,
											# and the others will use the cache.
											A__					:       Dict     =cached_features_file + """.lock"""
											with FileLock(lowerCAmelCase_			):
																	if os.path.exists(lowerCAmelCase_			) and not overwrite_cache:
																							logger.info(f"Loading features from cached file {cached_features_file}"			)
																							A__					:       Any     =torch.load(lowerCAmelCase_			)
																	else:
																							logger.info(f"Creating features from dataset file at {data_dir}"			)

																							A__					:       Optional[int]     =(
																							    processor.get_dev_examples(lowerCAmelCase_			) if evaluate else processor.get_train_examples(lowerCAmelCase_			)
																							)

																							logger.info("""Training examples: %s"""		,      len(lowerCAmelCase_			)			)
																							A__					:       Optional[Any]     =hans_convert_examples_to_features(lowerCAmelCase_		,      lowerCAmelCase_		,      lowerCAmelCase_		,      lowerCAmelCase_			)
																							logger.info("""Saving features into cached file %s"""		,      lowerCAmelCase_			)
																							torch.save(self.features		,      lowerCAmelCase_			)


					def __len__(				self	:						Optional[int]			)      ->		Optional[Any]:





											'''simple docstring'''
											return len(self.features			)


					def __getitem__(				self	:						str		,      lowerCAmelCase_	:						Union[str, Any]			)      ->		InputFeatures:





											'''simple docstring'''
											return self.features[i]



					def lowercase__						(				self	:						Dict			)      ->		List[str]:





											'''simple docstring'''
											return self.label_list


if is_tf_available():
		import tensorflow as tf



		class lowerCamelCase			:



					'''simple docstring'''






					__snake_case        =	42


					def __init__(				self	:						Optional[Any]		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						PreTrainedTokenizer		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						Optional[int] = 1_28		,      lowerCAmelCase_	:						Optional[int]=False		,      lowerCAmelCase_	:						bool = False		,      )      ->		Optional[Any]:





											'''simple docstring'''
											A__					:       List[Any]     =hans_processors[task]()
											A__					:       List[str]     =processor.get_labels()
											if tokenizer.__class__ in (
											    RobertaTokenizer,
											    RobertaTokenizerFast,
											    XLMRobertaTokenizer,
											    BartTokenizer,
											    BartTokenizerFast,
											):
																	# HACK(label indices are swapped in RoBERTa pretrained model)
																	A__   ,						A__					:       List[str]     =label_list[2], label_list[1]
											A__					:       Optional[int]     =label_list

											A__					:       Tuple     =processor.get_dev_examples(lowerCAmelCase_			) if evaluate else processor.get_train_examples(lowerCAmelCase_			)
											A__					:       Optional[Any]     =hans_convert_examples_to_features(lowerCAmelCase_		,      lowerCAmelCase_		,      lowerCAmelCase_		,      lowerCAmelCase_			)

											def gen():
																	for ex_index, ex in tqdm.tqdm(enumerate(self.features			)		,      desc="""convert examples to features"""			):
																							if ex_index % 1_00_00 == 0:
																													logger.info("""Writing example %d of %d""" % (ex_index, len(lowerCAmelCase_			))			)

																							yield (
																							    {
																							        "example_id": 0,
																							        "input_ids": ex.input_ids,
																							        "attention_mask": ex.attention_mask,
																							        "token_type_ids": ex.token_type_ids,
																							    },
																							    ex.label,
																							)

											A__					:       Optional[int]     =tf.data.Dataset.from_generator(
											    lowerCAmelCase_		,      (
											        {
											            """example_id""": tf.intaa,
											            """input_ids""": tf.intaa,
											            """attention_mask""": tf.intaa,
											            """token_type_ids""": tf.intaa,
											        },
											        tf.intaa,
											    )		,      (
											        {
											            """example_id""": tf.TensorShape([]			),
											            """input_ids""": tf.TensorShape([None, None]			),
											            """attention_mask""": tf.TensorShape([None, None]			),
											            """token_type_ids""": tf.TensorShape([None, None]			),
											        },
											        tf.TensorShape([]			),
											    )		,      )


					def lowercase__						(				self	:						Any			)      ->		Tuple:





											'''simple docstring'''
											return self.dataset


					def __len__(				self	:						List[Any]			)      ->		Optional[int]:





											'''simple docstring'''
											return len(self.features			)


					def __getitem__(				self	:						Optional[Any]		,      lowerCAmelCase_	:						List[str]			)      ->		InputFeatures:





											'''simple docstring'''
											return self.features[i]



					def lowercase__						(				self	:						List[Any]			)      ->		str:





											'''simple docstring'''
											return self.label_list



class lowerCamelCase			(  lowercase_						):



			'''simple docstring'''






			def lowercase__						(				self	:						List[str]		,      lowerCAmelCase_	:						Union[str, Any]			)      ->		List[Any]:





									'''simple docstring'''
									return self._create_examples(self._read_tsv(os.path.join(lowerCAmelCase_		,      """heuristics_train_set.txt"""			)			)		,      """train"""			)


			def lowercase__						(				self	:						int		,      lowerCAmelCase_	:						int			)      ->		Tuple:





									'''simple docstring'''
									return self._create_examples(self._read_tsv(os.path.join(lowerCAmelCase_		,      """heuristics_evaluation_set.txt"""			)			)		,      """dev"""			)


			def lowercase__						(				self	:						Optional[int]			)      ->		List[Any]:





									'''simple docstring'''
									return ["contradiction", "entailment", "neutral"]



			def lowercase__						(				self	:						Optional[Any]		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						int			)      ->		Dict:





									'''simple docstring'''
									A__					:       str     =[]
									for i, line in enumerate(lowerCAmelCase_			):
															if i == 0:
																					continue
															A__					:       List[Any]     ="""%s-%s""" % (set_type, line[0])
															A__					:       str     =line[5]
															A__					:       Optional[int]     =line[6]
															A__					:       Dict     =line[7][2:] if line[7].startswith("""ex"""			) else line[7]
															A__					:       Optional[Any]     =line[0]
															examples.append(InputExample(guid=lowerCAmelCase_		,      text_a=lowerCAmelCase_		,      text_b=lowerCAmelCase_		,      label=lowerCAmelCase_		,      pairID=lowerCAmelCase_			)			)
									return examples


def 						__lowerCamelCase	(       __snake_case					:		List[InputExample],		__snake_case					:		List[str],		__snake_case					:		int,		__snake_case					:		PreTrainedTokenizer,		)	->							Any:






						"""simple docstring"""





						A__					:       Dict     ={label: i for i, label in enumerate(__snake_case	)}

						A__					:       Optional[Any]     =[]
						for ex_index, example in tqdm.tqdm(enumerate(__snake_case	),		desc="""convert examples to features"""	):
												if ex_index % 10_000 == 0:
																		logger.info("""Writing example %d""" % (ex_index)	)

												A__					:       List[str]     =tokenizer(
												    example.text_a,		example.text_b,		add_special_tokens=__snake_case,		max_length=__snake_case,		padding="""max_length""",		truncation=__snake_case,		return_overflowing_tokens=__snake_case,		)

												A__					:       Dict     =label_map[example.label] if example.label in label_map else 0

												A__					:       Tuple     =int(example.pairID	)

												features.append(InputFeatures(**__snake_case,		label=__snake_case,		pairID=__snake_case	)	)

						for i, example in enumerate(examples[:5]	):
												logger.info("""*** Example ***"""	)
												logger.info(f"guid: {example}"	)
												logger.info(f"features: {features[i]}"	)

						return features


__snake_case			:     List[str]										=      {
    'hans': 3,
}
__snake_case			:     Optional[int]										=      {
    'hans': HansProcessor,
}




'''simple docstring'''



import math

__snake_case			:     List[Any]										=      10
__snake_case			:     Dict										=      7
__snake_case			:     str										=      BALLS_PER_COLOUR * NUM_COLOURS
def 						__lowerCamelCase	(       __snake_case					:		int = 20	)	->							str:






						"""simple docstring"""





						A__					:       Union[str, Any]     =math.comb(__snake_case,		__snake_case	)
						A__					:       str     =math.comb(NUM_BALLS - BALLS_PER_COLOUR,		__snake_case	)

						A__					:       Optional[int]     =NUM_COLOURS * (1 - missing_colour / total)

						return f"{result:.9f}"


if __name__ == "__main__":
		print(solution(20))

