"""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 lowerCamelCase		(unittest.TestCase   ):






					'''simple docstring'''


					a 						=		MODEL_FOR_MASKED_LM_MAPPING
					a 						=		TF_MODEL_FOR_MASKED_LM_MAPPING



					def       lowerCAmelCase_       (    self      :					Tuple		)				->							Union[str, Any]:
									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       lowerCAmelCase_       (    self      :					List[Any]		)				->							Union[str, Any]:
									SCREAMING_SNAKE_CASE__			=					pipeline(task="fill-mask" ,			model="sshleifer/tiny-distilroberta-base" ,			top_k=2 ,			framework="tf"		)
									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {"sequence": "My name is grouped", "score": 2.1e-05, "token": 38015, "token_str": " grouped"},
									        {"sequence": "My name is accuser", "score": 2.1e-05, "token": 25506, "token_str": " accuser"},
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("The largest city in France is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {
									            "sequence": "The largest city in France is grouped",
									            "score": 2.1e-05,
									            "token": 38015,
									            "token_str": " grouped",
									        },
									        {
									            "sequence": "The largest city in France is accuser",
									            "score": 2.1e-05,
									            "token": 25506,
									            "token_str": " accuser",
									        },
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>" ,			targets=[" Patrick", " Clara", " Teven"] ,			top_k=3		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {"sequence": "My name is Clara", "score": 2e-05, "token": 13606, "token_str": " Clara"},
									        {"sequence": "My name is Patrick", "score": 2e-05, "token": 3499, "token_str": " Patrick"},
									        {"sequence": "My name is Te", "score": 1.9e-05, "token": 2941, "token_str": " Te"},
									    ] ,			)



					@require_torch
					def       lowerCAmelCase_       (    self      :					Optional[Any]		)				->							List[str]:
									SCREAMING_SNAKE_CASE__			=					pipeline(task="fill-mask" ,			model="sshleifer/tiny-distilroberta-base" ,			top_k=2 ,			framework="pt"		)

									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {"sequence": "My name is Maul", "score": 2.2e-05, "token": 35676, "token_str": " Maul"},
									        {"sequence": "My name isELS", "score": 2.2e-05, "token": 16416, "token_str": "ELS"},
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("The largest city in France is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {
									            "sequence": "The largest city in France is Maul",
									            "score": 2.2e-05,
									            "token": 35676,
									            "token_str": " Maul",
									        },
									        {"sequence": "The largest city in France isELS", "score": 2.2e-05, "token": 16416, "token_str": "ELS"},
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>" ,			targets=[" Patrick", " Clara", " Teven"] ,			top_k=3		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        {"sequence": "My name is Patrick", "score": 2.1e-05, "token": 3499, "token_str": " Patrick"},
									        {"sequence": "My name is Te", "score": 2e-05, "token": 2941, "token_str": " Te"},
									        {"sequence": "My name is Clara", "score": 2e-05, "token": 13606, "token_str": " Clara"},
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask> <mask>" ,			top_k=2		)

									self.assertEqual(
									    nested_simplify(lowerCamelCase_ ,			decimals=6		) ,			[
									        [
									            {
									                "score": 2.2e-05,
									                "token": 35676,
									                "token_str": " Maul",
									                "sequence": "<s>My name is Maul<mask></s>",
									            },
									            {"score": 2.2e-05, "token": 16416, "token_str": "ELS", "sequence": "<s>My name isELS<mask></s>"},
									        ],
									        [
									            {
									                "score": 2.2e-05,
									                "token": 35676,
									                "token_str": " Maul",
									                "sequence": "<s>My name is<mask> Maul</s>",
									            },
									            {"score": 2.2e-05, "token": 16416, "token_str": "ELS", "sequence": "<s>My name is<mask>ELS</s>"},
									        ],
									    ] ,			)



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

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

									SCREAMING_SNAKE_CASE__			=					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(lowerCamelCase_ ,			lowerCamelCase_		)



					@slow
					@require_torch
					def       lowerCAmelCase_       (    self      :					Optional[int]		)				->							Optional[int]:
									SCREAMING_SNAKE_CASE__			=					pipeline(task="fill-mask" ,			model="distilroberta-base" ,			top_k=2 ,			framework="pt"		)
									self.run_large_test(lowerCamelCase_		)



					@slow
					@require_tf
					def       lowerCAmelCase_       (    self      :					Dict		)				->							Optional[Any]:
									SCREAMING_SNAKE_CASE__			=					pipeline(task="fill-mask" ,			model="distilroberta-base" ,			top_k=2 ,			framework="tf"		)
									self.run_large_test(lowerCamelCase_		)



					def       lowerCAmelCase_       (    self      :					Tuple ,			_snake_case      :					Dict		)				->							str:
									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_		) ,			[
									        {"sequence": "My name is John", "score": 0.008, "token": 610, "token_str": " John"},
									        {"sequence": "My name is Chris", "score": 0.007, "token": 1573, "token_str": " Chris"},
									    ] ,			)
									SCREAMING_SNAKE_CASE__			=					unmasker("The largest city in France is <mask>"		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_		) ,			[
									        {
									            "sequence": "The largest city in France is Paris",
									            "score": 0.251,
									            "token": 2201,
									            "token_str": " Paris",
									        },
									        {
									            "sequence": "The largest city in France is Lyon",
									            "score": 0.214,
									            "token": 12790,
									            "token_str": " Lyon",
									        },
									    ] ,			)

									SCREAMING_SNAKE_CASE__			=					unmasker("My name is <mask>" ,			targets=[" Patrick", " Clara", " Teven"] ,			top_k=3		)
									self.assertEqual(
									    nested_simplify(lowerCamelCase_		) ,			[
									        {"sequence": "My name is Patrick", "score": 0.005, "token": 3499, "token_str": " Patrick"},
									        {"sequence": "My name is Clara", "score": 0.000, "token": 13606, "token_str": " Clara"},
									        {"sequence": "My name is Te", "score": 0.000, "token": 2941, "token_str": " Te"},
									    ] ,			)



					@require_torch
					def       lowerCAmelCase_       (    self      :					Union[str, Any]		)				->							List[Any]:
									SCREAMING_SNAKE_CASE__			=					pipeline(task="fill-mask" ,			model="sshleifer/tiny-distilroberta-base" ,			framework="pt"		)
									SCREAMING_SNAKE_CASE__			=					None
									SCREAMING_SNAKE_CASE__			=					None
									self.run_pipeline_test(lowerCamelCase_ ,			[]		)



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



					def       lowerCAmelCase_       (    self      :					List[str] ,			_snake_case      :					Tuple ,			_snake_case      :					List[Any] ,			_snake_case      :					List[str]		)				->							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__			=					FillMaskPipeline(model=lowerCamelCase_ ,			tokenizer=lowerCamelCase_		)
									SCREAMING_SNAKE_CASE__			=					[
									    F"""This is another {tokenizer.mask_token} test""",
									]
									return fill_masker, examples



					def       lowerCAmelCase_       (    self      :					Any ,			_snake_case      :					Dict ,			_snake_case      :					List[Any]		)				->							Dict:
									SCREAMING_SNAKE_CASE__			=					fill_masker.tokenizer
									SCREAMING_SNAKE_CASE__			=					fill_masker.model

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

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

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

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

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



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

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

									# Score equivalence
									SCREAMING_SNAKE_CASE__			=					fill_masker(F"""This is a {tokenizer.mask_token}""" ,			targets=lowerCamelCase_		)
									SCREAMING_SNAKE_CASE__			=					[top_mask["""token_str"""] for top_mask in outputs]
									SCREAMING_SNAKE_CASE__			=					[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(lowerCamelCase_		) == set(lowerCamelCase_		):
													SCREAMING_SNAKE_CASE__			=					fill_masker(F"""This is a {tokenizer.mask_token}""" ,			targets=lowerCamelCase_		)
													SCREAMING_SNAKE_CASE__			=					[top_mask["""score"""] for top_mask in unmasked_targets]
													self.assertEqual(nested_simplify(lowerCamelCase_		) ,			nested_simplify(lowerCamelCase_		)		)

									# Raises with invalid
									with self.assertRaises(lowerCamelCase_		):
													SCREAMING_SNAKE_CASE__			=					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(lowerCamelCase_		):
																	SCREAMING_SNAKE_CASE__			=					fill_masker(F"""This is a {tokenizer.mask_token}""" ,			targets=[""]		)
													with self.assertRaises(lowerCamelCase_		):
																	SCREAMING_SNAKE_CASE__			=					fill_masker(F"""This is a {tokenizer.mask_token}""" ,			targets=""		)



					def       lowerCAmelCase_       (    self      :					Any ,			_snake_case      :					Dict ,			_snake_case      :					Any		)				->							Any:
									SCREAMING_SNAKE_CASE__			=					FillMaskPipeline(model=lowerCamelCase_ ,			tokenizer=lowerCamelCase_ ,			top_k=2		)
									SCREAMING_SNAKE_CASE__			=					fill_masker(F"""This is a {tokenizer.mask_token}"""		)
									self.assertEqual(
									    lowerCamelCase_ ,			[
									        {"sequence": ANY(lowerCamelCase_		), "score": ANY(lowerCamelCase_		), "token": ANY(lowerCamelCase_		), "token_str": ANY(lowerCamelCase_		)},
									        {"sequence": ANY(lowerCamelCase_		), "score": ANY(lowerCamelCase_		), "token": ANY(lowerCamelCase_		), "token_str": ANY(lowerCamelCase_		)},
									    ] ,			)

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



					def       lowerCAmelCase_       (    self      :					Dict ,			_snake_case      :					Tuple ,			_snake_case      :					Optional[int]		)				->							List[Any]:
									SCREAMING_SNAKE_CASE__			=					tokenizer.get_vocab()
									SCREAMING_SNAKE_CASE__			=					FillMaskPipeline(model=lowerCamelCase_ ,			tokenizer=lowerCamelCase_		)

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

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



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

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



					def       lowerCAmelCase_       (    self      :					List[str] ,			_snake_case      :					List[str] ,			_snake_case      :					Tuple		)				->							int:
									SCREAMING_SNAKE_CASE__			=					FillMaskPipeline(model=lowerCamelCase_ ,			tokenizer=lowerCamelCase_		)

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











'''simple docstring'''




import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer




class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	'''Wav2Vec2FeatureExtractor'''
					SCREAMING_SNAKE_CASE__				=	'''AutoTokenizer'''


					def __init__(						self				:			Optional[int]      ,						lowerCamelCase_				:			str      ,						lowerCamelCase_				:			Dict						):

							'''simple docstring'''



							super().__init__(lowerCamelCase_      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				int		=			self.feature_extractor
							SCREAMING_SNAKE_CASE :				List[Any]		=			False


					@classmethod
					def lowerCamelCase_			(						cls				:			int      ,						lowerCamelCase_				:			List[str]      ,						**lowerCamelCase_				:			Any						):

							'''simple docstring'''



							try:
									return super().from_pretrained(lowerCamelCase_      ,						**lowerCamelCase_						)
							except OSError:
									warnings.warn(
									    f'''Loading a tokenizer inside {cls.__name__} from a config that does not'''
									    """ include a `tokenizer_class` attribute is deprecated and will be """
									    """removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'`"""
									    """ attribute to either your `config.json` or `tokenizer_config.json` """
									    """file to suppress this warning: """      ,						lowerCamelCase_      ,						)

									SCREAMING_SNAKE_CASE :				Optional[Any]		=			WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase_      ,						**lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Dict		=			WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase_      ,						**lowerCamelCase_						)

									return cls(feature_extractor=lowerCamelCase_      ,						tokenizer=lowerCamelCase_						)


					def __call__(						self				:			List[Any]      ,						*lowerCamelCase_				:			str      ,						**lowerCamelCase_				:			int						):

							'''simple docstring'''



							if self._in_target_context_manager:
									return self.current_processor(*lowerCamelCase_      ,						**lowerCamelCase_						)

							if "raw_speech" in kwargs:
									warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""						)
									SCREAMING_SNAKE_CASE :				Dict		=			kwargs.pop("""raw_speech"""						)
							else:
									SCREAMING_SNAKE_CASE :				Any		=			kwargs.pop("""audio"""      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Tuple		=			kwargs.pop("""sampling_rate"""      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				int		=			kwargs.pop("""text"""      ,						lowerCamelCase_						)
							if len(lowerCamelCase_						) > 0:
									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			args[0]
									SCREAMING_SNAKE_CASE :				Dict		=			args[1:]

							if audio is None and text is None:
									raise ValueError("""You need to specify either an `audio` or `text` input to process."""						)

							if audio is not None:
									SCREAMING_SNAKE_CASE :				str		=			self.feature_extractor(lowerCamelCase_      ,						*lowerCamelCase_      ,						sampling_rate=lowerCamelCase_      ,						**lowerCamelCase_						)
							if text is not None:
									SCREAMING_SNAKE_CASE :				List[Any]		=			self.tokenizer(lowerCamelCase_      ,						**lowerCamelCase_						)

							if text is None:
									return inputs
							elif audio is None:
									return encodings
							else:
									SCREAMING_SNAKE_CASE :				List[str]		=			encodings["""input_ids"""]
									return inputs


					def lowerCamelCase_			(						self				:			Optional[Any]      ,						*lowerCamelCase_				:			Tuple      ,						**lowerCamelCase_				:			Dict						):

							'''simple docstring'''



							if self._in_target_context_manager:
									return self.current_processor.pad(*lowerCamelCase_      ,						**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				str		=			kwargs.pop("""input_features"""      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Dict		=			kwargs.pop("""labels"""      ,						lowerCamelCase_						)
							if len(lowerCamelCase_						) > 0:
									SCREAMING_SNAKE_CASE :				Optional[int]		=			args[0]
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			args[1:]

							if input_features is not None:
									SCREAMING_SNAKE_CASE :				Any		=			self.feature_extractor.pad(lowerCamelCase_      ,						*lowerCamelCase_      ,						**lowerCamelCase_						)
							if labels is not None:
									SCREAMING_SNAKE_CASE :				int		=			self.tokenizer.pad(lowerCamelCase_      ,						**lowerCamelCase_						)

							if labels is None:
									return input_features
							elif input_features is None:
									return labels
							else:
									SCREAMING_SNAKE_CASE :				Dict		=			labels["""input_ids"""]
									return input_features


					def lowerCamelCase_			(						self				:			Optional[int]      ,						*lowerCamelCase_				:			List[str]      ,						**lowerCamelCase_				:			Optional[Any]						):

							'''simple docstring'''



							return self.tokenizer.batch_decode(*lowerCamelCase_      ,						**lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			List[str]      ,						*lowerCamelCase_				:			Optional[int]      ,						**lowerCamelCase_				:			Optional[int]						):

							'''simple docstring'''



							return self.tokenizer.decode(*lowerCamelCase_      ,						**lowerCamelCase_						)



					@contextmanager
					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							warnings.warn(
							    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
							    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
							    """your audio inputs, or in a separate call."""						)
							SCREAMING_SNAKE_CASE :				int		=			True
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.tokenizer
							yield
							SCREAMING_SNAKE_CASE :				int		=			self.feature_extractor
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			False



