

"""simple docstring"""

import concurrent.futures
import json
import os
import shutil
import tempfile
import unittest

from transformers import AutoTokenizer, PreTrainedTokenizerFast
from transformers.testing_utils import require_tokenizers

from ..test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class  __a				(	__magic_name__					,  unittest.TestCase					):





       """simple docstring"""


       __UpperCamelCase				:			Optional[int]          =	PreTrainedTokenizerFast
       __UpperCamelCase				:			Optional[Any]          =	False
       __UpperCamelCase				:			Optional[int]          =	True
       __UpperCamelCase				:			Tuple          =	'tokenizer_file'






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							str    =							False  # because we don't have pretrained_vocab_files_map
        super().setUp()
        lowerCAmelCase__      :							Union[str, Any]    =							True

        lowerCAmelCase__      :							str    =							["robot-test/dummy-tokenizer-fast", "robot-test/dummy-tokenizer-wordlevel"]
        lowerCAmelCase__      :							int    =							"SaulLu/dummy-tokenizer-bytelevel-bpe"

        # Inclusion of 2 tokenizers to test different types of models (Unigram and WordLevel for the moment)
        lowerCAmelCase__      :							Dict    =							[(PreTrainedTokenizerFast, model_path, {}) for model_path in model_paths]

        lowerCAmelCase__      :							Dict    =							PreTrainedTokenizerFast.from_pretrained(model_paths[0]      )
        tokenizer.save_pretrained(self.tmpdirname      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        pass






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        pass






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        pass






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        pass






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							Optional[int]    =							self.tmpdirname
        # Here we want to test the 2 available tokenizers that use 2 different types of models: Unigram and WordLevel.
        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""      ):
          try:
           lowerCAmelCase__      :							Tuple    =							tempfile.mkdtemp()
           lowerCAmelCase__      :							List[str]    =							self.rust_tokenizer_class.from_pretrained(snake_case ,				**snake_case      )

           tokenizer.save_pretrained(self.tmpdirname      )
           super().test_training_new_tokenizer()
          finally:
           # Even if the test fails, we must be sure that the folder is deleted and that the default tokenizer
           # is restored
           shutil.rmtree(self.tmpdirname      )
           lowerCAmelCase__      :							Optional[int]    =							tmpdirname_orig






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							Tuple    =							self.tmpdirname
        # Here we want to test the 2 available tokenizers that use 2 different types of models: Unigram and WordLevel.
        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""      ):
          try:
           lowerCAmelCase__      :							Optional[int]    =							tempfile.mkdtemp()
           lowerCAmelCase__      :							List[Any]    =							self.rust_tokenizer_class.from_pretrained(snake_case ,				**snake_case      )

           tokenizer.save_pretrained(self.tmpdirname      )
           super().test_training_new_tokenizer_with_special_tokens_change()
          finally:
           # Even if the test fails, we must be sure that the folder is deleted and that the default tokenizer
           # is restored
           shutil.rmtree(self.tmpdirname      )
           lowerCAmelCase__      :							Optional[int]    =							tmpdirname_orig






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							List[Any]    =							self.rust_tokenizer_class.from_pretrained(self.bytelevel_bpe_model_name      )

        lowerCAmelCase__      :							List[Any]    =							("a" for _ in range(1_000      ))
        lowerCAmelCase__      :							Tuple    =							tokenizer.train_new_from_iterator(text_iterator=snake_case ,				length=1_000 ,				vocab_size=50      )

        lowerCAmelCase__      :							Union[str, Any]    =							new_tokenizer.encode("a🤗"      )
        self.assertEqual(snake_case ,				[64, 172, 253, 97, 245]      )






@require_tokenizers
class  __a				(	unittest.TestCase					):





       """simple docstring"""


       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							Dict    =							AutoTokenizer.from_pretrained("bert-base-cased"      )
        lowerCAmelCase__      :							Optional[Any]    =							json.loads(tokenizer._tokenizer.to_str()      )
        lowerCAmelCase__      :							Optional[int]    =							len(snake_case      )

        with tempfile.TemporaryDirectory() as tmp_dir:
         # Hack to save this in the tokenizer_config.json
         lowerCAmelCase__      :							int    =							["tokenizer.4.0.0.json"]
         tokenizer.save_pretrained(snake_case      )
         json.dump(snake_case ,				open(os.path.join(snake_case ,				"tokenizer.4.0.0.json"      ) ,				"w"      )      )

         # This should pick the new tokenizer file as the version of Transformers is > 4.0.0
         lowerCAmelCase__      :							List[Any]    =							AutoTokenizer.from_pretrained(snake_case      )
         self.assertEqual(len(snake_case      ) ,				len(snake_case      ) + 1      )
         lowerCAmelCase__      :							Tuple    =							json.loads(new_tokenizer._tokenizer.to_str()      )
         self.assertIn("huggingface" ,				json_tokenizer["model"]["vocab"]      )

         # Will need to be adjusted if we reach v42 and this test is still here.
         # Should pick the old tokenizer file as the version of Transformers is < 4.0.0
         shutil.move(os.path.join(snake_case ,				"tokenizer.4.0.0.json"      ) ,				os.path.join(snake_case ,				"tokenizer.42.0.0.json"      )      )
         lowerCAmelCase__      :							str    =							["tokenizer.42.0.0.json"]
         tokenizer.save_pretrained(snake_case      )
         lowerCAmelCase__      :							Union[str, Any]    =							AutoTokenizer.from_pretrained(snake_case      )
         self.assertEqual(len(snake_case      ) ,				len(snake_case      )      )
         lowerCAmelCase__      :							List[str]    =							json.loads(new_tokenizer._tokenizer.to_str()      )
         self.assertNotIn("huggingface" ,				json_tokenizer["model"]["vocab"]      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							Dict    =							"hf-internal-testing/test-two-tokenizers"

        # This should pick the new tokenizer file as the version of Transformers is > 4.0.0
        lowerCAmelCase__      :							List[str]    =							AutoTokenizer.from_pretrained(snake_case      )
        self.assertEqual(len(snake_case      ) ,				28_997      )
        lowerCAmelCase__      :							Optional[int]    =							json.loads(tokenizer._tokenizer.to_str()      )
        self.assertIn("huggingface" ,				json_tokenizer["model"]["vocab"]      )

        # Testing an older version by monkey-patching the version in the module it's used.
        import transformers as old_transformers

        lowerCAmelCase__      :							List[str]    =							"3.0.0"
        lowerCAmelCase__      :							Any    =							old_transformers.models.auto.AutoTokenizer.from_pretrained(snake_case      )
        self.assertEqual(len(snake_case      ) ,				28_996      )
        lowerCAmelCase__      :							Dict    =							json.loads(old_tokenizer._tokenizer.to_str()      )
        self.assertNotIn("huggingface" ,				json_tokenizer["model"]["vocab"]      )






@require_tokenizers
class  __a				(	unittest.TestCase					):





       """simple docstring"""


       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        lowerCAmelCase__      :							Optional[Any]    =							PreTrainedTokenizerFast.from_pretrained("robot-test/dummy-tokenizer-wordlevel"      )
        lowerCAmelCase__      :							Optional[Any]    =							"The Matrix is a 1999 science fiction action film."

        with concurrent.futures.ThreadPoolExecutor() as executor:
         lowerCAmelCase__      :							Union[str, Any]    =							[executor.submit(self.fetch ,				snake_case ,				snake_case      ) for i in range(10      )]
         lowerCAmelCase__      :							Union[str, Any]    =							[future.result() for future in futures]
         self.assertEqual(snake_case ,				[[1, 10, 0, 8, 0, 18, 0, 0, 0, 2] for i in range(10      )]      )






       def  SCREAMING_SNAKE_CASE_  (      self ,				snake_case ,				snake_case      ):





        """simple docstring"""

        return tokenizer.encode(snake_case ,				truncation="longest_first" ,				padding="longest"      )









"""simple docstring"""

from itertools import product



def 			SCREAMING_SNAKE_CASE       (   lowercase__ = 1_5      ) ->	int:
 lowerCAmelCase__      :							float    =							0.0
 lowerCAmelCase__      :							float
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							tuple[int, ...]

 for series in product(range(2      )				,				repeat=lowercase__      ):
  lowerCAmelCase__      :							Optional[int]    =							series.count(1      )
  lowerCAmelCase__      :							Dict    =							num_turns - num_blue
  if num_red >= num_blue:
   continue
  lowerCAmelCase__      :							Dict    =							1.0
  for ind, col in enumerate(lowercase__				,				2      ):
   if col == 0:
    prob *= (ind - 1) / ind
   else:
    prob *= 1 / ind

  total_prob += prob

 return int(1 / total_prob      )


if __name__ == "__main__":
    print(f"{solution() = }")






