code: 
  
  
  '''simple docstring'''
  
  import tempfile
  import unittest
  
  from transformers import DPRConfig, is_torch_available
  from transformers.testing_utils import require_torch, slow, torch_device
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  							import torch
  
  							from transformers import DPRContextEncoder, DPRQuestionEncoder, DPRReader, DPRReaderTokenizer
  							from transformers.models.dpr.modeling_dpr import (
  							    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
  							    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
  							    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
  							)
  class _lowerCamelCase :
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(      self	:		List[str]						,  _A	:		Tuple						,  _A	:		List[Any]=13						,  _A	:		Union[str, Any]=7						,  _A	:		Tuple=False						,  _A	:		Dict=True						,  _A	:		Optional[int]=True						,  _A	:		Optional[Any]=True						,  _A	:		Optional[int]=99						,  _A	:		Optional[Any]=32						,  _A	:		Tuple=5						,  _A	:		List[Any]=4						,  _A	:		int=37						,  _A	:		Dict="gelu"						,  _A	:		Tuple=0.1						,  _A	:		Tuple=0.1						,  _A	:		Tuple=512						,  _A	:		Optional[int]=16						,  _A	:		int=2						,  _A	:		Tuple=0.02						,  _A	:		Optional[int]=3						,  _A	:		str=4						,  _A	:		List[Any]=None						,  _A	:		Optional[Any]=0						,  )						->				Optional[int]:
  			__magic_name__ :					int  			=  parent
  			__magic_name__ :					Any  			=  batch_size
  			__magic_name__ :					Optional[Any]  			=  seq_length
  			__magic_name__ :					str  			=  is_training
  			__magic_name__ :					Optional[Any]  			=  use_input_mask
  			__magic_name__ :					List[Any]  			=  use_token_type_ids
  			__magic_name__ :					Any  			=  use_labels
  			__magic_name__ :					Dict  			=  vocab_size
  			__magic_name__ :					int  			=  hidden_size
  			__magic_name__ :					Dict  			=  num_hidden_layers
  			__magic_name__ :					Optional[Any]  			=  num_attention_heads
  			__magic_name__ :					Dict  			=  intermediate_size
  			__magic_name__ :					Optional[int]  			=  hidden_act
  			__magic_name__ :					Optional[Any]  			=  hidden_dropout_prob
  			__magic_name__ :					List[str]  			=  attention_probs_dropout_prob
  			__magic_name__ :					Any  			=  max_position_embeddings
  			__magic_name__ :					List[Any]  			=  type_vocab_size
  			__magic_name__ :					Optional[Any]  			=  type_sequence_label_size
  			__magic_name__ :					int  			=  initializer_range
  			__magic_name__ :					Optional[Any]  			=  num_labels
  			__magic_name__ :					Tuple  			=  num_choices
  			__magic_name__ :					int  			=  scope
  			__magic_name__ :					Optional[int]  			=  projection_dim
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				int:
  			__magic_name__ :					Optional[int]  			=  ids_tensor([self.batch_size, self.seq_length]						,  self.vocab_size    )
  
  			__magic_name__ :					Optional[int]  			=  None
  			if self.use_input_mask:
  				__magic_name__ :					Dict  			=  random_attention_mask([self.batch_size, self.seq_length]    )
  
  			__magic_name__ :					Any  			=  None
  			if self.use_token_type_ids:
  				__magic_name__ :					List[Any]  			=  ids_tensor([self.batch_size, self.seq_length]						,  self.type_vocab_size    )
  
  			__magic_name__ :					Any  			=  None
  			__magic_name__ :					List[Any]  			=  None
  			__magic_name__ :					Optional[int]  			=  None
  			if self.use_labels:
  				__magic_name__ :					Tuple  			=  ids_tensor([self.batch_size]						,  self.type_sequence_label_size    )
  				__magic_name__ :					Dict  			=  ids_tensor([self.batch_size, self.seq_length]						,  self.num_labels    )
  				__magic_name__ :					Union[str, Any]  			=  ids_tensor([self.batch_size]						,  self.num_choices    )
  
  			__magic_name__ :					Optional[Any]  			=  self.get_config()
  
  			return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Any:
  			return DPRConfig(
  			    projection_dim=self.projection_dim						,  vocab_size=self.vocab_size						,  hidden_size=self.hidden_size						,  num_hidden_layers=self.num_hidden_layers						,  num_attention_heads=self.num_attention_heads						,  intermediate_size=self.intermediate_size						,  hidden_act=self.hidden_act						,  hidden_dropout_prob=self.hidden_dropout_prob						,  attention_probs_dropout_prob=self.attention_probs_dropout_prob						,  max_position_embeddings=self.max_position_embeddings						,  type_vocab_size=self.type_vocab_size						,  initializer_range=self.initializer_range						,  )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]						,  _A	:		Any						,  _A	:		int						,  _A	:		Optional[int]						,  _A	:		Optional[int]						,  _A	:		List[str]						,  _A	:		Tuple						,  _A	:		int    )						->				Optional[Any]:
  			__magic_name__ :					Optional[int]  			=  DPRContextEncoder(config=_A    )
  			model.to(_A    )
  			model.eval()
  			__magic_name__ :					Any  			=  model(_A						,  attention_mask=_A						,  token_type_ids=_A    )
  			__magic_name__ :					Optional[int]  			=  model(_A						,  token_type_ids=_A    )
  			__magic_name__ :					str  			=  model(_A    )
  			self.parent.assertEqual(result.pooler_output.shape						,  (self.batch_size, self.projection_dim or self.hidden_size)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]						,  _A	:		Any						,  _A	:		Union[str, Any]						,  _A	:		List[Any]						,  _A	:		str						,  _A	:		Tuple						,  _A	:		Optional[Any]						,  _A	:		Tuple    )						->				List[Any]:
  			__magic_name__ :					Tuple  			=  DPRQuestionEncoder(config=_A    )
  			model.to(_A    )
  			model.eval()
  			__magic_name__ :					Dict  			=  model(_A						,  attention_mask=_A						,  token_type_ids=_A    )
  			__magic_name__ :					Union[str, Any]  			=  model(_A						,  token_type_ids=_A    )
  			__magic_name__ :					Optional[Any]  			=  model(_A    )
  			self.parent.assertEqual(result.pooler_output.shape						,  (self.batch_size, self.projection_dim or self.hidden_size)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Tuple						,  _A	:		List[str]						,  _A	:		Tuple						,  _A	:		Optional[Any]						,  _A	:		Union[str, Any]						,  _A	:		Any						,  _A	:		Dict						,  _A	:		Union[str, Any]    )						->				List[str]:
  			__magic_name__ :					Dict  			=  DPRReader(config=_A    )
  			model.to(_A    )
  			model.eval()
  			__magic_name__ :					Optional[Any]  			=  model(
  			    _A						,  attention_mask=_A						,  )
  
  			self.parent.assertEqual(result.start_logits.shape						,  (self.batch_size, self.seq_length)    )
  			self.parent.assertEqual(result.end_logits.shape						,  (self.batch_size, self.seq_length)    )
  			self.parent.assertEqual(result.relevance_logits.shape						,  (self.batch_size,)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		int    )						->				List[str]:
  			__magic_name__ :					List[str]  			=  self.prepare_config_and_inputs()
  			(
  			    (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       (
  			    __magic_name__
  			)			,       
  			) :					Dict  			=  config_and_inputs
  			__magic_name__ :					Union[str, Any]  			=  {'input_ids': input_ids}
  			return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class _lowerCamelCase (		lowercase__	,  lowercase__	,  unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		A_			:    Union[str, Any]   					=       (
  		    (
  		        DPRContextEncoder,
  		        DPRQuestionEncoder,
  		        DPRReader,
  		    )
  		    if is_torch_available()
  		    else ()
  		)
  		A_			:    Dict   					=       {"""feature-extraction""": DPRQuestionEncoder} if is_torch_available() else {}
  
  		A_			:    str   					=       False
  		A_			:    Optional[Any]   					=       False  # why?
  		A_			:    Optional[Any]   					=       False
  		A_			:    Tuple   					=       False
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Optional[int]:
  			__magic_name__ :					str  			=  DPRModelTester(self    )
  			__magic_name__ :					str  			=  ConfigTester(self						,  config_class=_A						,  hidden_size=37    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				Any:
  			self.config_tester.run_common_tests()
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Tuple    )						->				Dict:
  			__magic_name__ :					List[Any]  			=  self.model_tester.prepare_config_and_inputs()
  			self.model_tester.create_and_check_context_encoder(*_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				Union[str, Any]:
  			__magic_name__ :					Union[str, Any]  			=  self.model_tester.prepare_config_and_inputs()
  			self.model_tester.create_and_check_question_encoder(*_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Tuple    )						->				Any:
  			__magic_name__ :					Optional[Any]  			=  self.model_tester.prepare_config_and_inputs()
  			self.model_tester.create_and_check_reader(*_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]    )						->				Dict:
  			__magic_name__ :					str  			=  self.model_tester.prepare_config_and_inputs()[0]
  
  			__magic_name__ :					int  			=  DPRQuestionEncoder(config=_A    )
  			model.to(_A    )
  			model.eval()
  
  			with tempfile.TemporaryDirectory() as tmp_dirname:
  				model.save_pretrained(_A    )
  				__magic_name__ :					Union[str, Any]  			=  DPRQuestionEncoder.from_pretrained(_A						,  projection_dim=512    )
  
  			self.assertIsNotNone(_A    )
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				List[str]:
  			for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  				__magic_name__ :					Any  			=  DPRContextEncoder.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  
  			for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  				__magic_name__ :					List[Any]  			=  DPRContextEncoder.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  
  			for model_name in DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  				__magic_name__ :					str  			=  DPRQuestionEncoder.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  
  			for model_name in DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  				__magic_name__ :					Any  			=  DPRReader.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  
  
  
  
  
  
  
  @require_torch
  class _lowerCamelCase (		unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		Tuple    )						->				List[Any]:
  			__magic_name__ :					Union[str, Any]  			=  DPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'						,  return_dict=_A    )
  			model.to(_A    )
  
  			__magic_name__ :					Tuple  			=  torch.tensor(
  			    [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]						,  dtype=torch.long						,  device=_A    )  # [CLS] hello, is my dog cute? [SEP]
  			__magic_name__ :					List[str]  			=  model(_A    )[0]  # embedding shape = (1, 768)
  			# compare the actual values for a slice.
  			__magic_name__ :					Dict  			=  torch.tensor(
  			    [
  			        [
  			            0.0323_6253,
  			            0.1275_3335,
  			            0.1681_8509,
  			            0.0027_9786,
  			            0.389_6933,
  			            0.2426_4945,
  			            0.217_8971,
  			            -0.0233_5227,
  			            -0.0848_1959,
  			            -0.1432_4117,
  			        ]
  			    ]						,  dtype=torch.float						,  device=_A						,  )
  			self.assertTrue(torch.allclose(output[:, :10]						,  _A						,  atol=1E-4    )    )
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				Dict:
  			__magic_name__ :					Union[str, Any]  			=  DPRReaderTokenizer.from_pretrained('facebook/dpr-reader-single-nq-base'    )
  			__magic_name__ :					Optional[Any]  			=  DPRReader.from_pretrained('facebook/dpr-reader-single-nq-base'    )
  			model.to(_A    )
  
  			__magic_name__ :					Any  			=  tokenizer(
  			    questions='What is love ?'						,  titles='Haddaway'						,  texts='What Is Love is a song recorded by the artist Haddaway'						,  padding=_A						,  return_tensors='pt'						,  )
  			encoded_inputs.to(_A    )
  
  			__magic_name__ :					Dict  			=  model(**_A    )
  
  			# compare the actual values for a slice.
  			__magic_name__ :					Dict  			=  torch.tensor(
  			    [[-10.3005, -10.7765, -11.4872, -11.6841, -11.9312, -10.3002, -9.8544, -11.7378, -12.0821, -10.2975]]						,  dtype=torch.float						,  device=_A						,  )
  
  			__magic_name__ :					List[str]  			=  torch.tensor(
  			    [[-11.0684, -11.7041, -11.5397, -10.3465, -10.8791, -6.8443, -11.9959, -11.0364, -10.0096, -6.8405]]						,  dtype=torch.float						,  device=_A						,  )
  			self.assertTrue(torch.allclose(outputs.start_logits[:, :10]						,  _A						,  atol=1E-4    )    )
  			self.assertTrue(torch.allclose(outputs.end_logits[:, :10]						,  _A						,  atol=1E-4    )    )
style_context: 
  
  
  '''simple docstring'''
  
  import os
  import pickle
  import tempfile
  import unittest
  from typing import Callable, Optional
  
  import numpy as np
  
  from transformers import (
      BatchEncoding,
      BertTokenizer,
      BertTokenizerFast,
      PreTrainedTokenizer,
      PreTrainedTokenizerFast,
      TensorType,
      TokenSpan,
      is_tokenizers_available,
  )
  from transformers.models.gpta.tokenization_gpta import GPTaTokenizer
  from transformers.testing_utils import CaptureStderr, require_flax, require_tf, require_tokenizers, require_torch, slow
  
  
  if is_tokenizers_available():
  							from tokenizers import Tokenizer
  							from tokenizers.models import WordPiece
  class _lowerCamelCase (		unittest.TestCase							):
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Any						,  _A	:		Optional[Any]    )						->				Optional[int]:
  			__magic_name__ :					Optional[int]  			=  list(tokenizer_class.max_model_input_sizes.keys()    )
  			for model_name in sa_models[:1]:
  				__magic_name__ :					List[str]  			=  tokenizer_class.from_pretrained(_A    )
  				self.assertIsNotNone(_A    )
  				self.assertIsInstance(_A						,  _A    )
  				self.assertIsInstance(_A						,  _A    )
  
  				for special_tok in tokenizer.all_special_tokens:
  					self.assertIsInstance(_A						,  _A    )
  					__magic_name__ :					Optional[Any]  			=  tokenizer.convert_tokens_to_ids(_A    )
  					self.assertIsInstance(_A						,  _A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[Any]						,  _A	:		BatchEncoding						,  _A	:		Optional[Callable] = None    )						->				Tuple:
  			__magic_name__ :					Union[str, Any]  			=  pickle.dumps(_A    )
  			self.assertIsNotNone(_A    )
  
  			__magic_name__ :					Optional[Any]  			=  pickle.loads(_A    )
  
  			# Ensure is_fast is correctly restored
  			self.assertEqual(be_restored.is_fast						,  be_original.is_fast    )
  
  			# Ensure encodings are potentially correctly restored
  			if be_original.is_fast:
  				self.assertIsNotNone(be_restored.encodings    )
  			else:
  				self.assertIsNone(be_restored.encodings    )
  
  			# Ensure the keys are the same
  			for original_v, restored_v in zip(be_original.values()						,  be_restored.values()    ):
  				if equal_op:
  					self.assertTrue(equal_op(_A						,  _A    )    )
  				else:
  					self.assertEqual(_A						,  _A    )
  
  
  
  
  
  
  
  		@slow
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Optional[Any]:
  			self.check_tokenizer_from_pretrained(_A    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				List[Any]:
  			self.assertEqual(TensorType('tf'    )						,  TensorType.TENSORFLOW    )
  			self.assertEqual(TensorType('pt'    )						,  TensorType.PYTORCH    )
  			self.assertEqual(TensorType('np'    )						,  TensorType.NUMPY    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Optional[int]:
  			import numpy as np
  
  			__magic_name__ :					Dict  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					str  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  
  			# Python no tensor
  			with self.subTest('BatchEncoding (Python, return_tensors=None)'    ):
  				self.assert_dump_and_restore(tokenizer_p('Small example to encode'    )    )
  
  			with self.subTest('BatchEncoding (Python, return_tensors=NUMPY)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_p('Small example to encode'						,  return_tensors=TensorType.NUMPY    )						,  np.array_equal    )
  
  			with self.subTest('BatchEncoding (Rust, return_tensors=None)'    ):
  				self.assert_dump_and_restore(tokenizer_r('Small example to encode'    )    )
  
  			with self.subTest('BatchEncoding (Rust, return_tensors=NUMPY)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_r('Small example to encode'						,  return_tensors=TensorType.NUMPY    )						,  np.array_equal    )
  
  
  
  
  
  
  
  		@require_tf
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				List[str]:
  			import tensorflow as tf
  
  			def tf_array_equals(_A	:		str						,  _A	:		Union[str, Any]    ):
  				return tf.reduce_all(tf.equal(_A						,  _A    )    )
  
  			__magic_name__ :					str  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Optional[Any]  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  
  			with self.subTest('BatchEncoding (Python, return_tensors=TENSORFLOW)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_p('Small example to encode'						,  return_tensors=TensorType.TENSORFLOW    )						,  _A    )
  
  			with self.subTest('BatchEncoding (Rust, return_tensors=TENSORFLOW)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_r('Small example to encode'						,  return_tensors=TensorType.TENSORFLOW    )						,  _A    )
  
  
  
  
  
  
  
  		@require_torch
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Any    )						->				List[str]:
  			import torch
  
  			__magic_name__ :					Union[str, Any]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Optional[int]  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  
  			with self.subTest('BatchEncoding (Python, return_tensors=PYTORCH)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_p('Small example to encode'						,  return_tensors=TensorType.PYTORCH    )						,  torch.equal    )
  
  			with self.subTest('BatchEncoding (Rust, return_tensors=PYTORCH)'    ):
  				self.assert_dump_and_restore(
  				    tokenizer_r('Small example to encode'						,  return_tensors=TensorType.PYTORCH    )						,  torch.equal    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		List[str]    )						->				Dict:
  			__magic_name__ :					Optional[int]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Dict  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  
  			with self.subTest('Python Tokenizer'    ):
  				self.assertFalse(tokenizer_p('Small example to_encode'    ).is_fast    )
  
  			with self.subTest('Rust Tokenizer'    ):
  				self.assertTrue(tokenizer_r('Small example to_encode'    ).is_fast    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]    )						->				Optional[int]:
  			__magic_name__ :					Optional[int]  			=  BertTokenizerFast.from_pretrained('bert-base-cased'    )
  			__magic_name__ :					Tuple  			=  tokenizer_r(['Test', '\xad', 'test']						,  is_split_into_words=_A    )
  
  			self.assertEqual(encoded.word_to_tokens(0    )						,  TokenSpan(start=1						,  end=2    )    )
  			self.assertEqual(encoded.word_to_tokens(1    )						,  _A    )
  			self.assertEqual(encoded.word_to_tokens(2    )						,  TokenSpan(start=2						,  end=3    )    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		Optional[int]    )						->				Optional[Any]:
  			__magic_name__ :					Any  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					Dict  			=  batch.convert_to_tensors(tensor_type='np'    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (2, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (2,)    )
  			# test converting the converted
  			with CaptureStderr() as cs:
  				__magic_name__ :					Any  			=  batch.convert_to_tensors(tensor_type='np'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Optional[Any]  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					List[Any]  			=  batch.convert_to_tensors(tensor_type='np'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_torch
  		def      __lowerCAmelCase	(      self	:		Union[str, Any]    )						->				Any:
  			__magic_name__ :					Optional[int]  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					List[Any]  			=  batch.convert_to_tensors(tensor_type='pt'    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (2, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (2,)    )
  			# test converting the converted
  			with CaptureStderr() as cs:
  				__magic_name__ :					Union[str, Any]  			=  batch.convert_to_tensors(tensor_type='pt'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Any  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					str  			=  batch.convert_to_tensors(tensor_type='pt'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_tf
  		def      __lowerCAmelCase	(      self	:		Optional[Any]    )						->				List[str]:
  			__magic_name__ :					str  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					List[str]  			=  batch.convert_to_tensors(tensor_type='tf'    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (2, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (2,)    )
  			# test converting the converted
  			with CaptureStderr() as cs:
  				__magic_name__ :					Optional[int]  			=  batch.convert_to_tensors(tensor_type='tf'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					Union[str, Any]  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					Union[str, Any]  			=  batch.convert_to_tensors(tensor_type='tf'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		@require_flax
  		def      __lowerCAmelCase	(      self	:		str    )						->				Optional[Any]:
  			__magic_name__ :					List[Any]  			=  BatchEncoding({'inputs': [[1, 2, 3], [4, 5, 6]], 'labels': [0, 1]}    )
  			__magic_name__ :					int  			=  batch.convert_to_tensors(tensor_type='jax'    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (2, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (2,)    )
  			# test converting the converted
  			with CaptureStderr() as cs:
  				__magic_name__ :					Optional[Any]  			=  batch.convert_to_tensors(tensor_type='jax'    )
  			self.assertFalse(len(cs.err    )						,  msg=F'should have no warning, but got {cs.err}'    )
  
  			__magic_name__ :					str  			=  BatchEncoding({'inputs': [1, 2, 3], 'labels': 0}    )
  			__magic_name__ :					Dict  			=  batch.convert_to_tensors(tensor_type='jax'						,  prepend_batch_axis=_A    )
  			self.assertEqual(tensor_batch['inputs'].shape						,  (1, 3)    )
  			self.assertEqual(tensor_batch['labels'].shape						,  (1,)    )
  
  
  
  
  
  
  
  		def      __lowerCAmelCase	(      self	:		str    )						->				int:
  			__magic_name__ :					int  			=  [{'input_ids': np.array([0, 1, 2]    )}, {'input_ids': np.array([0, 1, 2, 3]    )}]
  			__magic_name__ :					Dict  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					Optional[int]  			=  tokenizer.pad(_A						,  padding=_A    )
  			self.assertTrue(isinstance(batch['input_ids']						,  np.ndarray    )    )
  			self.assertEqual(batch['input_ids'].tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  			__magic_name__ :					Dict  			=  tokenizer.pad(_A						,  padding=_A						,  return_tensors='np'    )
  			self.assertTrue(isinstance(batch['input_ids']						,  np.ndarray    )    )
  			self.assertEqual(batch['input_ids'].tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  
  
  
  
  
  
  
  		@require_torch
  		def      __lowerCAmelCase	(      self	:		List[Any]    )						->				str:
  			import torch
  
  			__magic_name__ :					List[str]  			=  [{'input_ids': torch.tensor([0, 1, 2]    )}, {'input_ids': torch.tensor([0, 1, 2, 3]    )}]
  			__magic_name__ :					List[str]  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					List[Any]  			=  tokenizer.pad(_A						,  padding=_A    )
  			self.assertTrue(isinstance(batch['input_ids']						,  torch.Tensor    )    )
  			self.assertEqual(batch['input_ids'].tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  			__magic_name__ :					Union[str, Any]  			=  tokenizer.pad(_A						,  padding=_A						,  return_tensors='pt'    )
  			self.assertTrue(isinstance(batch['input_ids']						,  torch.Tensor    )    )
  			self.assertEqual(batch['input_ids'].tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  
  
  
  
  
  
  
  		@require_tf
  		def      __lowerCAmelCase	(      self	:		Any    )						->				Optional[int]:
  			import tensorflow as tf
  
  			__magic_name__ :					Tuple  			=  [{'input_ids': tf.constant([0, 1, 2]    )}, {'input_ids': tf.constant([0, 1, 2, 3]    )}]
  			__magic_name__ :					Any  			=  BertTokenizer.from_pretrained('bert-base-cased'    )
  
  			__magic_name__ :					Any  			=  tokenizer.pad(_A						,  padding=_A    )
  			self.assertTrue(isinstance(batch['input_ids']						,  tf.Tensor    )    )
  			self.assertEqual(batch['input_ids'].numpy().tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  			__magic_name__ :					Union[str, Any]  			=  tokenizer.pad(_A						,  padding=_A						,  return_tensors='tf'    )
  			self.assertTrue(isinstance(batch['input_ids']						,  tf.Tensor    )    )
  			self.assertEqual(batch['input_ids'].numpy().tolist()						,  [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Any    )						->				str:
  			__magic_name__ :					str  			=  Tokenizer(WordPiece(unk_token='[UNK]'    )    )
  			PreTrainedTokenizerFast(tokenizer_object=_A    )
  
  
  
  
  
  
  
  		@require_tokenizers
  		def      __lowerCAmelCase	(      self	:		Dict    )						->				Any:
  			__magic_name__ :					List[Any]  			=  Tokenizer(WordPiece(unk_token='[UNK]'    )    )
  			with tempfile.TemporaryDirectory() as tmpdirname:
  				bert_tokenizer.save(os.path.join(_A						,  'tokenizer.json'    )    )
  				PreTrainedTokenizerFast(tokenizer_file=os.path.join(_A						,  'tokenizer.json'    )    )