






'''simple docstring'''
import gc
import unittest

from transformers import MODEL_FOR_MASKED_LM_MAPPING, TF_MODEL_FOR_MASKED_LM_MAPPING, FillMaskPipeline, pipeline
from transformers.pipelines import PipelineException
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_gpu,
    slow,
)

from .test_pipelines_common import ANY






@is_pipeline_test
class        __SCREAMING_SNAKE_CASE (     unittest.TestCase			):
 snake_case_												=							MODEL_FOR_MASKED_LM_MAPPING
 snake_case_												=							TF_MODEL_FOR_MASKED_LM_MAPPING




 def        __magic_name__		( self		:							Optional[Any] )		->  Tuple:
       super().tearDown()
       # clean-up as much as possible GPU memory occupied by PyTorch
       gc.collect()
       if is_torch_available():
             import torch

             torch.cuda.empty_cache()




 @require_tf
 def        __magic_name__		( self		:							str )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Any													=pipeline(task='''fill-mask'''   , model='''sshleifer/tiny-distilroberta-base'''   , top_k=2   , framework='''tf''' )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=unmasker('''My name is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {'''sequence''': '''My name is grouped''', '''score''': 2.1e-05, '''token''': 3_80_15, '''token_str''': ''' grouped'''},
               {'''sequence''': '''My name is accuser''', '''score''': 2.1e-05, '''token''': 2_55_06, '''token_str''': ''' accuser'''},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=unmasker('''The largest city in France is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {
                   '''sequence''': '''The largest city in France is grouped''',
                   '''score''': 2.1e-05,
                   '''token''': 3_80_15,
                   '''token_str''': ''' grouped''',
               },
               {
                   '''sequence''': '''The largest city in France is accuser''',
                   '''score''': 2.1e-05,
                   '''token''': 2_55_06,
                   '''token_str''': ''' accuser''',
               },
           ]   , )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=unmasker('''My name is <mask>'''   , targets=[''' Patrick''', ''' Clara''', ''' Teven''']   , top_k=3 )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {'''sequence''': '''My name is Clara''', '''score''': 2e-05, '''token''': 1_36_06, '''token_str''': ''' Clara'''},
               {'''sequence''': '''My name is Patrick''', '''score''': 2e-05, '''token''': 34_99, '''token_str''': ''' Patrick'''},
               {'''sequence''': '''My name is Te''', '''score''': 1.9e-05, '''token''': 29_41, '''token_str''': ''' Te'''},
           ]   , )




 @require_torch
 def        __magic_name__		( self		:							Optional[int] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=pipeline(task='''fill-mask'''   , model='''sshleifer/tiny-distilroberta-base'''   , top_k=2   , framework='''pt''' )

       SCREAMING_SNAKE_CASE__       :			Tuple													=unmasker('''My name is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {'''sequence''': '''My name is Maul''', '''score''': 2.2e-05, '''token''': 3_56_76, '''token_str''': ''' Maul'''},
               {'''sequence''': '''My name isELS''', '''score''': 2.2e-05, '''token''': 1_64_16, '''token_str''': '''ELS'''},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			str													=unmasker('''The largest city in France is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {
                   '''sequence''': '''The largest city in France is Maul''',
                   '''score''': 2.2e-05,
                   '''token''': 3_56_76,
                   '''token_str''': ''' Maul''',
               },
               {'''sequence''': '''The largest city in France isELS''', '''score''': 2.2e-05, '''token''': 1_64_16, '''token_str''': '''ELS'''},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=unmasker('''My name is <mask>'''   , targets=[''' Patrick''', ''' Clara''', ''' Teven''']   , top_k=3 )
       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               {'''sequence''': '''My name is Patrick''', '''score''': 2.1e-05, '''token''': 34_99, '''token_str''': ''' Patrick'''},
               {'''sequence''': '''My name is Te''', '''score''': 2e-05, '''token''': 29_41, '''token_str''': ''' Te'''},
               {'''sequence''': '''My name is Clara''', '''score''': 2e-05, '''token''': 1_36_06, '''token_str''': ''' Clara'''},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Any													=unmasker('''My name is <mask> <mask>'''   , top_k=2 )

       self.assertEqual(
           nested_simplify(__lowercase   , decimals=6 )   , [
               [
                   {
                       '''score''': 2.2e-05,
                       '''token''': 3_56_76,
                       '''token_str''': ''' Maul''',
                       '''sequence''': '''<s>My name is Maul<mask></s>''',
                   },
                   {'''score''': 2.2e-05, '''token''': 1_64_16, '''token_str''': '''ELS''', '''sequence''': '''<s>My name isELS<mask></s>'''},
               ],
               [
                   {
                       '''score''': 2.2e-05,
                       '''token''': 3_56_76,
                       '''token_str''': ''' Maul''',
                       '''sequence''': '''<s>My name is<mask> Maul</s>''',
                   },
                   {'''score''': 2.2e-05, '''token''': 1_64_16, '''token_str''': '''ELS''', '''sequence''': '''<s>My name is<mask>ELS</s>'''},
               ],
           ]   , )




 @require_torch_gpu
 def        __magic_name__		( self		:							str )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Any													=pipeline('''fill-mask'''   , model='''hf-internal-testing/tiny-random-distilbert'''   , device=0   , framework='''pt''' )

       # convert model to fp16
       pipe.model.half()

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=pipe('''Paris is the [MASK] of France.''' )
       # We actually don't care about the result, we just want to make sure
       # it works, meaning the float16 tensor got casted back to float32
       # for postprocessing.
       self.assertIsInstance(__lowercase   , __lowercase )




 @slow
 @require_torch
 def        __magic_name__		( self		:							str )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=pipeline(task='''fill-mask'''   , model='''distilroberta-base'''   , top_k=2   , framework='''pt''' )
       self.run_large_test(__lowercase )




 @slow
 @require_tf
 def        __magic_name__		( self		:							Optional[int] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=pipeline(task='''fill-mask'''   , model='''distilroberta-base'''   , top_k=2   , framework='''tf''' )
       self.run_large_test(__lowercase )




 def        __magic_name__		( self		:							Any   , __lowercase		:							Tuple )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Dict													=unmasker('''My name is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase )   , [
               {'''sequence''': '''My name is John''', '''score''': 0.008, '''token''': 6_10, '''token_str''': ''' John'''},
               {'''sequence''': '''My name is Chris''', '''score''': 0.007, '''token''': 15_73, '''token_str''': ''' Chris'''},
           ]   , )
       SCREAMING_SNAKE_CASE__       :			str													=unmasker('''The largest city in France is <mask>''' )
       self.assertEqual(
           nested_simplify(__lowercase )   , [
               {
                   '''sequence''': '''The largest city in France is Paris''',
                   '''score''': 0.251,
                   '''token''': 22_01,
                   '''token_str''': ''' Paris''',
               },
               {
                   '''sequence''': '''The largest city in France is Lyon''',
                   '''score''': 0.214,
                   '''token''': 1_27_90,
                   '''token_str''': ''' Lyon''',
               },
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Dict													=unmasker('''My name is <mask>'''   , targets=[''' Patrick''', ''' Clara''', ''' Teven''']   , top_k=3 )
       self.assertEqual(
           nested_simplify(__lowercase )   , [
               {'''sequence''': '''My name is Patrick''', '''score''': 0.005, '''token''': 34_99, '''token_str''': ''' Patrick'''},
               {'''sequence''': '''My name is Clara''', '''score''': 0.000, '''token''': 1_36_06, '''token_str''': ''' Clara'''},
               {'''sequence''': '''My name is Te''', '''score''': 0.000, '''token''': 29_41, '''token_str''': ''' Te'''},
           ]   , )




 @require_torch
 def        __magic_name__		( self		:							str )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=pipeline(task='''fill-mask'''   , model='''sshleifer/tiny-distilroberta-base'''   , framework='''pt''' )
       SCREAMING_SNAKE_CASE__       :			Tuple													=None
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=None
       self.run_pipeline_test(__lowercase   , [] )




 @require_tf
 def        __magic_name__		( self		:							Any )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=pipeline(task='''fill-mask'''   , model='''sshleifer/tiny-distilroberta-base'''   , framework='''tf''' )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=None
       SCREAMING_SNAKE_CASE__       :			str													=None
       self.run_pipeline_test(__lowercase   , [] )




 def        __magic_name__		( self		:							str   , __lowercase		:							Optional[int]   , __lowercase		:							Any   , __lowercase		:							Union[str, Any] )		->  List[str]:
       if tokenizer is None or tokenizer.mask_token_id is None:
             self.skipTest('''The provided tokenizer has no mask token, (probably reformer or wav2vec2)''' )

       SCREAMING_SNAKE_CASE__       :			int													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=[
           F"This is another {tokenizer.mask_token} test",
       ]
       return fill_masker, examples




 def        __magic_name__		( self		:							Optional[Any]   , __lowercase		:							List[str]   , __lowercase		:							Tuple )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			List[str]													=fill_masker.tokenizer
       SCREAMING_SNAKE_CASE__       :			Dict													=fill_masker.model

       SCREAMING_SNAKE_CASE__       :			Dict													=fill_masker(
           F"This is a {tokenizer.mask_token}"   , )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Dict													=fill_masker([F"This is a {tokenizer.mask_token}"] )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Dict													=fill_masker([F"This is a {tokenizer.mask_token}", F"Another {tokenizer.mask_token} great test."] )
       self.assertEqual(
           __lowercase   , [
               [
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               ],
               [
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               ],
           ]   , )

       with self.assertRaises(__lowercase ):
             fill_masker([None] )
       # No mask_token is not supported
       with self.assertRaises(__lowercase ):
             fill_masker('''This is''' )

       self.run_test_top_k(__lowercase   , __lowercase )
       self.run_test_targets(__lowercase   , __lowercase )
       self.run_test_top_k_targets(__lowercase   , __lowercase )
       self.fill_mask_with_duplicate_targets_and_top_k(__lowercase   , __lowercase )
       self.fill_mask_with_multiple_masks(__lowercase   , __lowercase )




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							int   , __lowercase		:							Dict )		->  Any:
       SCREAMING_SNAKE_CASE__       :			Tuple													=tokenizer.get_vocab()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=sorted(vocab.keys() )[:2]
       # Pipeline argument
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase   , targets=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=fill_masker(F"This is a {tokenizer.mask_token}" )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													={vocab[el] for el in targets}
       self.assertEqual({el['''token'''] for el in outputs}   , __lowercase )
       SCREAMING_SNAKE_CASE__       :			Dict													=[tokenizer.decode([x] ) for x in target_ids]
       self.assertEqual({el['''token_str'''] for el in outputs}   , set(__lowercase ) )

       # Call argument
       SCREAMING_SNAKE_CASE__       :			Any													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets=__lowercase )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													={vocab[el] for el in targets}
       self.assertEqual({el['''token'''] for el in outputs}   , __lowercase )
       SCREAMING_SNAKE_CASE__       :			str													=[tokenizer.decode([x] ) for x in target_ids]
       self.assertEqual({el['''token_str'''] for el in outputs}   , set(__lowercase ) )

       # Score equivalence
       SCREAMING_SNAKE_CASE__       :			int													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Tuple													=[top_mask['''token_str'''] for top_mask in outputs]
       SCREAMING_SNAKE_CASE__       :			List[Any]													=[top_mask['''score'''] for top_mask in outputs]

       # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
       if set(__lowercase ) == set(__lowercase ):
             SCREAMING_SNAKE_CASE__       :			Tuple													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets=__lowercase )
             SCREAMING_SNAKE_CASE__       :			int													=[top_mask['''score'''] for top_mask in unmasked_targets]
             self.assertEqual(nested_simplify(__lowercase )   , nested_simplify(__lowercase ) )

       # Raises with invalid
       with self.assertRaises(__lowercase ):
             SCREAMING_SNAKE_CASE__       :			List[Any]													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets=[] )
       # For some tokenizers, `""` is actually in the vocabulary and the expected error won't raised
       if "" not in tokenizer.get_vocab():
             with self.assertRaises(__lowercase ):
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets=[''''''] )
             with self.assertRaises(__lowercase ):
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=fill_masker(F"This is a {tokenizer.mask_token}"   , targets='''''' )




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							List[str]   , __lowercase		:							List[Any] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			str													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase   , top_k=2 )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=fill_masker(F"This is a {tokenizer.mask_token}" )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )

       SCREAMING_SNAKE_CASE__       :			Dict													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Any													=fill_masker(F"This is a {tokenizer.mask_token}"   , top_k=2 )
       self.assertEqual(
           __lowercase   , [
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
           ]   , )
       self.assertEqual(nested_simplify(__lowercase )   , nested_simplify(__lowercase ) )




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							Optional[int]   , __lowercase		:							Any )		->  Any:
       SCREAMING_SNAKE_CASE__       :			str													=tokenizer.get_vocab()
       SCREAMING_SNAKE_CASE__       :			str													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )

       # top_k=2, ntargets=3
       SCREAMING_SNAKE_CASE__       :			List[str]													=sorted(vocab.keys() )[:3]
       SCREAMING_SNAKE_CASE__       :			Dict													=fill_masker(F"This is a {tokenizer.mask_token}"   , top_k=2   , targets=__lowercase )

       # If we use the most probably targets, and filter differently, we should still
       # have the same results
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=[el['''token_str'''] for el in sorted(__lowercase   , key=lambda __lowercase : x["score"]   , reverse=__lowercase )]
       # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
       if set(__lowercase ).issubset(__lowercase ):
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=fill_masker(F"This is a {tokenizer.mask_token}"   , top_k=3   , targets=__lowercase )
             # They should yield exactly the same result
             self.assertEqual(nested_simplify(__lowercase )   , nested_simplify(__lowercase ) )




 def        __magic_name__		( self		:							str   , __lowercase		:							int   , __lowercase		:							Tuple )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Dict													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer.get_vocab()
       # String duplicates + id duplicates
       SCREAMING_SNAKE_CASE__       :			int													=sorted(vocab.keys() )[:3]
       SCREAMING_SNAKE_CASE__       :			List[str]													=[targets[0], targets[1], targets[0], targets[2], targets[1]]
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=fill_masker(F"My name is {tokenizer.mask_token}"   , targets=__lowercase   , top_k=10 )

       # The target list contains duplicates, so we can't output more
       # than them
       self.assertEqual(len(__lowercase )   , 3 )




 def        __magic_name__		( self		:							List[str]   , __lowercase		:							Any   , __lowercase		:							Union[str, Any] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Any													=FillMaskPipeline(model=__lowercase   , tokenizer=__lowercase )

       SCREAMING_SNAKE_CASE__       :			Tuple													=fill_masker(
           F"This is a {tokenizer.mask_token} {tokenizer.mask_token} {tokenizer.mask_token}"   , top_k=2 )
       self.assertEqual(
           __lowercase   , [
               [
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               ],
               [
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               ],
               [
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
                   {'''sequence''': ANY(__lowercase ), '''score''': ANY(__lowercase ), '''token''': ANY(__lowercase ), '''token_str''': ANY(__lowercase )},
               ],
           ]   , )







'''simple docstring'''
from decimal import Decimal, getcontext
from math import ceil, factorial





def 	_a(					UpperCamelCase__			:  int							):




      '''simple docstring'''






      if not isinstance(UpperCamelCase__,		UpperCamelCase__							):
            raise TypeError('''Undefined for non-integers'''							)
      elif precision < 1:
            raise ValueError('''Undefined for non-natural numbers'''							)

      SCREAMING_SNAKE_CASE__       :			Optional[Any]													=precision
      SCREAMING_SNAKE_CASE__       :			int													=ceil(precision / 1_4							)
      SCREAMING_SNAKE_CASE__       :			int													=4_2_6_8_8_0 * Decimal(1_0_0_0_5							).sqrt()
      SCREAMING_SNAKE_CASE__       :			Tuple													=1
      SCREAMING_SNAKE_CASE__       :			Any													=1_3_5_9_1_4_0_9
      SCREAMING_SNAKE_CASE__       :			List[Any]													=Decimal(UpperCamelCase__							)
      for k in range(1,		UpperCamelCase__							):
            SCREAMING_SNAKE_CASE__       :			str													=factorial(6 * k							) // (factorial(3 * k							) * factorial(UpperCamelCase__							) ** 3)
            linear_term += 5_4_5_1_4_0_1_3_4
            exponential_term *= -2_6_2_5_3_7_4_1_2_6_4_0_7_6_8_0_0_0
            partial_sum += Decimal(multinomial_term * linear_term							) / exponential_term
      return str(constant_term / partial_sum							)[:-1]


if __name__ == "__main__":
  a_					=	5_0
  print(F'''The first {n} digits of pi is: {pi(n)}''')