



"""simple docstring"""







import numpy as np

def 	lowerCAmelCase__      (  lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__      )			->				Optional[int]:
							A    =       n_draws * class_counts / class_counts.sum()
							# floored means we don't overshoot n_samples, but probably undershoot
							A    =       np.floor(lowerCamelCase__      )
							# we add samples according to how much "left over" probability
							# they had, until we arrive at n_samples
							A    =       int(n_draws - floored.sum()      )
							if need_to_add > 0:
														A    =       continuous - floored
														A    =       np.sort(np.unique(lowerCamelCase__      )      )[::-1]
														# add according to remainder, but break ties
														# randomly to avoid biases
														for value in values:
																					((A)   ,	)    =       np.where(remainder == value      )
																					# if we need_to_add less than what's in inds
																					# we draw randomly from them.
																					# if we need to add more, we add them all and
																					# go to the next value
																					A    =       min(len(lowerCamelCase__      )					,   lowerCamelCase__      )
																					A    =       rng.choice(lowerCamelCase__					,   size=lowerCamelCase__					,   replace=lowerCamelCase__      )
																					floored[inds] += 1
																					need_to_add -= add_now
																					if need_to_add == 0:
																												break
							return floored.astype(np.intaa      )

def 	lowerCAmelCase__      (  lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__=10      )			->				Union[str, Any]:
							A   ,	A    =       np.unique(lowerCamelCase__					,   return_inverse=lowerCamelCase__      )
							A    =       classes.shape[0]
							A    =       np.bincount(lowerCamelCase__      )
							if np.min(lowerCamelCase__      ) < 2:
														raise ValueError('Minimum class count error'      )
							if n_train < n_classes:
														raise ValueError(
														    'The train_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_train, n_classes)      )
							if n_test < n_classes:
														raise ValueError(
														    'The test_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_test, n_classes)      )
							A    =       np.split(np.argsort(lowerCamelCase__					,   kind='mergesort'      )					,   np.cumsum(lowerCamelCase__      )[:-1]      )
							for _ in range(lowerCamelCase__      ):
														A    =       approximate_mode(lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__      )
														A    =       class_counts - n_i
														A    =       approximate_mode(lowerCamelCase__					,   lowerCamelCase__					,   lowerCamelCase__      )

														A    =       []
														A    =       []

														for i in range(lowerCamelCase__      ):
																					A    =       rng.permutation(class_counts[i]      )
																					A    =       class_indices[i].take(lowerCamelCase__					,   mode='clip'      )
																					train.extend(perm_indices_class_i[: n_i[i]]      )
																					test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]]      )
														A    =       rng.permutation(lowerCamelCase__      )
														A    =       rng.permutation(lowerCamelCase__      )

														yield train, test








"""simple docstring"""







import os

from ...utils import logging
from .utils import DataProcessor, InputExample


A     =      logging.get_logger(__name__)






class   UpperCAmelCase__		(   UpperCamelCase  ):



		def __init__(			self	:     List[str]   ,				snake_case	:     List[Any]   ,				snake_case	:     str=None					)      ->    Tuple:






									'''simple docstring'''

									A    =       language
									A    =       train_language



		def        A_		(			self	:     Optional[int]   ,				snake_case	:     Any					)      ->    Union[str, Any]:






									'''simple docstring'''

									A    =       self.language if self.train_language is None else self.train_language
									A    =       self._read_tsv(os.path.join(snake_case   ,				f"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""					)					)
									A    =       []
									for i, line in enumerate(snake_case					):
																if i == 0:
																							continue
																A    =       f"""train-{i}"""
																A    =       line[0]
																A    =       line[1]
																A    =       'contradiction' if line[2] == 'contradictory' else line[2]
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training input {text_a} is not a string"""					)
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training input {text_b} is not a string"""					)
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training label {label} is not a string"""					)
																examples.append(InputExample(guid=snake_case   ,				text_a=snake_case   ,				text_b=snake_case   ,				label=snake_case					)					)
									return examples



		def        A_		(			self	:     int   ,				snake_case	:     int					)      ->    Optional[int]:






									'''simple docstring'''

									A    =       self._read_tsv(os.path.join(snake_case   ,				'XNLI-1.0/xnli.test.tsv'					)					)
									A    =       []
									for i, line in enumerate(snake_case					):
																if i == 0:
																							continue
																A    =       line[0]
																if language != self.language:
																							continue
																A    =       f"""test-{i}"""
																A    =       line[6]
																A    =       line[7]
																A    =       line[1]
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training input {text_a} is not a string"""					)
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training input {text_b} is not a string"""					)
																if not isinstance(snake_case   ,				snake_case					):
																							raise ValueError(f"""Training label {label} is not a string"""					)
																examples.append(InputExample(guid=snake_case   ,				text_a=snake_case   ,				text_b=snake_case   ,				label=snake_case					)					)
									return examples



		def        A_		(			self	:     Any					)      ->    List[Any]:






									'''simple docstring'''

									return ["contradiction", "entailment", "neutral"]



A     =      {
    'xnli': XnliProcessor,
}

A     =      {
    'xnli': 'classification',
}

A     =      {
    'xnli': 3,
}



