code: 
  
  
  
  import json
  import os
  import tempfile
  
  from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  
  if is_torch_available():
  	import numpy as np
  	import torch
  
  if is_vision_available():
  	from PIL import Image
  
  
  
  
  def   lowerCamelCase_       (					UpperCAmelCase__       ,    UpperCAmelCase__=False       ,    UpperCAmelCase__=False       ,    UpperCAmelCase__=False      ):
  
  
  
  						"""simple docstring"""
  
  
  
  
  						assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
  						a_					=		[]
  						for i in range(image_processor_tester.batch_size      ):
  												if equal_resolution:
  																		a_					=		a_					=		image_processor_tester.max_resolution
  												else:
  																		# To avoid getting image width/height 0
  																		a_					=		image_processor_tester.min_resolution
  																		if getattr(_A       ,    """size_divisor"""       ,    _A      ):
  																								# If `size_divisor` is defined, the image needs to have width/size >= `size_divisor`
  																								a_					=		max(image_processor_tester.size_divisor       ,    _A      )
  																		a_			,   a_					=		np.random.choice(np.arange(_A       ,    image_processor_tester.max_resolution      )       ,    2      )
  												image_inputs.append(
  												    np.random.randint(255       ,    size=(image_processor_tester.num_channels, width, height)       ,    dtype=np.uinta      )      )
  
  						if not numpify and not torchify:
  												# PIL expects the channel dimension as last dimension
  												a_					=		[Image.fromarray(np.moveaxis(_A       ,    0       ,    -1      )      ) for image in image_inputs]
  
  						if torchify:
  												a_					=		[torch.from_numpy(_A      ) for image in image_inputs]
  
  						return image_inputs
  
  
  
  
  def   lowerCamelCase_       (					UpperCAmelCase__       ,    UpperCAmelCase__=10       ,    UpperCAmelCase__=10       ,    UpperCAmelCase__=False       ,    UpperCAmelCase__=False      ):
  
  
  
  						"""simple docstring"""
  
  
  
  
  						a_					=		[]
  						for i in range(image_processor_tester.num_frames      ):
  												video.append(np.random.randint(255       ,    size=(image_processor_tester.num_channels, width, height)       ,    dtype=np.uinta      )      )
  
  						if not numpify and not torchify:
  												# PIL expects the channel dimension as last dimension
  												a_					=		[Image.fromarray(np.moveaxis(_A       ,    0       ,    -1      )      ) for frame in video]
  
  						if torchify:
  												a_					=		[torch.from_numpy(_A      ) for frame in video]
  
  						return video
  
  
  
  
  def   lowerCamelCase_       (					UpperCAmelCase__       ,    UpperCAmelCase__=False       ,    UpperCAmelCase__=False       ,    UpperCAmelCase__=False      ):
  
  
  
  						"""simple docstring"""
  
  
  
  
  						assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
  						a_					=		[]
  						for i in range(image_processor_tester.batch_size      ):
  												if equal_resolution:
  																		a_					=		a_					=		image_processor_tester.max_resolution
  												else:
  																		a_			,   a_					=		np.random.choice(
  																		    np.arange(image_processor_tester.min_resolution       ,    image_processor_tester.max_resolution      )       ,    2      )
  																		a_					=		prepare_video(
  																		    image_processor_tester=_A       ,    width=_A       ,    height=_A       ,    numpify=_A       ,    torchify=_A       ,    )
  												video_inputs.append(_A      )
  
  						return video_inputs
  
  
  
  
  
  class        lowercase_				:
  
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  
  
  
  
  							snake_case_        =		None
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  													a_					=		json.loads(image_processor.to_json_string()		)
  													for key, value in self.image_processor_dict.items():
  																			self.assertEqual(obj[key]			,    lowercase_		)
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  
  													with tempfile.TemporaryDirectory() as tmpdirname:
  																			a_					=		os.path.join(lowercase_			,    """image_processor.json"""		)
  																			image_processor_first.to_json_file(lowercase_		)
  																			a_					=		self.image_processing_class.from_json_file(lowercase_		)
  
  													self.assertEqual(image_processor_second.to_dict()			,    image_processor_first.to_dict()		)
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  
  													with tempfile.TemporaryDirectory() as tmpdirname:
  																			a_					=		image_processor_first.save_pretrained(lowercase_		)[0]
  																			check_json_file_has_correct_format(lowercase_		)
  																			a_					=		self.image_processing_class.from_pretrained(lowercase_		)
  
  													self.assertEqual(image_processor_second.to_dict()			,    image_processor_first.to_dict()		)
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class()
  													self.assertIsNotNone(lowercase_		)
  
  
  
  
  
  
  							@require_torch
  							@require_vision
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													if self.test_cast_dtype is not None:
  																			# Initialize image_processor
  																			a_					=		self.image_processing_class(**self.image_processor_dict		)
  
  																			# create random PyTorch tensors
  																			a_					=		prepare_image_inputs(self.image_processor_tester			,    equal_resolution=lowercase_			,    torchify=lowercase_		)
  
  																			a_					=		image_processor(lowercase_			,    return_tensors="""pt"""		)
  																			# for layoutLM compatiblity
  																			self.assertEqual(encoding.pixel_values.device			,    torch.device("""cpu"""		)		)
  																			self.assertEqual(encoding.pixel_values.dtype			,    torch.floataa		)
  
  																			a_					=		image_processor(lowercase_			,    return_tensors="""pt"""		).to(torch.floataa		)
  																			self.assertEqual(encoding.pixel_values.device			,    torch.device("""cpu"""		)		)
  																			self.assertEqual(encoding.pixel_values.dtype			,    torch.floataa		)
  
  																			a_					=		image_processor(lowercase_			,    return_tensors="""pt"""		).to("""cpu"""			,    torch.bfloataa		)
  																			self.assertEqual(encoding.pixel_values.device			,    torch.device("""cpu"""		)		)
  																			self.assertEqual(encoding.pixel_values.dtype			,    torch.bfloataa		)
  
  																			with self.assertRaises(lowercase_		):
  																									a_					=		image_processor(lowercase_			,    return_tensors="""pt"""		).to(torch.bfloataa			,    """cpu"""		)
  
  																			# Try with text + image feature
  																			a_					=		image_processor(lowercase_			,    return_tensors="""pt"""		)
  																			encoding.update({"""input_ids""": torch.LongTensor([[1, 2, 3], [4, 5, 6]]		)}		)
  																			a_					=		encoding.to(torch.floataa		)
  
  																			self.assertEqual(encoding.pixel_values.device			,    torch.device("""cpu"""		)		)
  																			self.assertEqual(encoding.pixel_values.dtype			,    torch.floataa		)
  																			self.assertEqual(encoding.input_ids.dtype			,    torch.long		)
style_context: 
  
  
  import os
  import unittest
  
  from transformers import MPNetTokenizerFast
  from transformers.models.mpnet.tokenization_mpnet import VOCAB_FILES_NAMES, MPNetTokenizer
  from transformers.testing_utils import require_tokenizers, slow
  
  from ...test_tokenization_common import TokenizerTesterMixin
  
  
  
  
  
  @require_tokenizers
  class        lowercase_				( UpperCamelCase__			,unittest.TestCase):
  
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  
  
  
  
  							snake_case_        =		MPNetTokenizer
  							snake_case_        =		MPNetTokenizerFast
  							snake_case_        =		True
  							snake_case_        =		True
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													super().setUp()
  
  													a_					=		[
  													    """[UNK]""",
  													    """[CLS]""",
  													    """[SEP]""",
  													    """[PAD]""",
  													    """[MASK]""",
  													    """want""",
  													    """##want""",
  													    """##ed""",
  													    """wa""",
  													    """un""",
  													    """runn""",
  													    """##ing""",
  													    """,""",
  													    """low""",
  													    """lowest""",
  													]
  													a_					=		os.path.join(self.tmpdirname			,    VOCAB_FILES_NAMES["""vocab_file"""]		)
  													with open(self.vocab_file			,    """w"""			,    encoding="""utf-8"""		) as vocab_writer:
  																			vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]		)		)
  
  
  							def 						lowercase__     (   self			,    _UpperCAmelCase		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		"""UNwant\u00E9d,running"""
  													a_					=		"""unwanted, running"""
  													return input_text, output_text
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.tokenizer_class(self.vocab_file		)
  
  													a_					=		tokenizer.tokenize("""UNwant\u00E9d,running"""		)
  													self.assertListEqual(_UpperCAmelCase			,    ["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]		)
  													self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase		)			,    [9, 6, 7, 12, 10, 11]		)
  
  
  
  
  
  
  							@slow
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.tokenizer_class.from_pretrained("""microsoft/mpnet-base"""		)
  
  													a_					=		tokenizer.encode("""sequence builders"""			,    add_special_tokens=_UpperCAmelCase		)
  													a_					=		tokenizer.encode("""multi-sequence build"""			,    add_special_tokens=_UpperCAmelCase		)
  
  													a_					=		tokenizer.build_inputs_with_special_tokens(_UpperCAmelCase		)
  													a_					=		tokenizer.build_inputs_with_special_tokens(_UpperCAmelCase			,    _UpperCAmelCase		)
  
  													assert encoded_sentence == [0] + text + [2]
  													assert encoded_pair == [0] + text + [2] + [2] + text_a + [2]