



"""simple docstring"""






import json
import os
import unittest

from transformers.models.roc_bert.tokenization_roc_bert import (
    VOCAB_FILES_NAMES,
    RoCBertBasicTokenizer,
    RoCBertTokenizer,
    RoCBertWordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english



@require_tokenizers
class 			A__   (  __SCREAMING_SNAKE_CASE  ,		unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	RoCBertTokenizer
	SCREAMING_SNAKE_CASE          =	None
	SCREAMING_SNAKE_CASE          =	False
	SCREAMING_SNAKE_CASE          =	True
	SCREAMING_SNAKE_CASE          =	filter_non_english

	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       List[str]:

				"""simple docstring"""

				super().setUp()

				__lowerCAmelCase      :  List[str]												=       ["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "你", "好", "是", "谁", "a", "b", "c", "d"]
				__lowerCAmelCase      :  int												=       {}
				__lowerCAmelCase      :  Any												=       {}
				for i, value in enumerate(_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase      :  Dict												=       i
							__lowerCAmelCase      :  int												=       i
				__lowerCAmelCase      :  Optional[Any]												=       os.path.join(self.tmpdirname       ,			VOCAB_FILES_NAMES["vocab_file"])
				__lowerCAmelCase      :  Tuple												=       os.path.join(self.tmpdirname       ,			VOCAB_FILES_NAMES["word_shape_file"])
				__lowerCAmelCase      :  Tuple												=       os.path.join(self.tmpdirname       ,			VOCAB_FILES_NAMES["word_pronunciation_file"])
				with open(self.vocab_file       ,			"w"       ,			encoding="utf-8") as vocab_writer:
							vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))
				with open(self.word_shape_file       ,			"w"       ,			encoding="utf-8") as word_shape_writer:
							json.dump(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			ensure_ascii=_SCREAMING_SNAKE_CASE)
				with open(self.word_pronunciation_file       ,			"w"       ,			encoding="utf-8") as word_pronunciation_writer:
							json.dump(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			ensure_ascii=_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       self.tokenizer_class(self.vocab_file       ,			self.word_shape_file       ,			self.word_pronunciation_file)

				__lowerCAmelCase      :  Tuple												=       tokenizer.tokenize("你好[SEP]你是谁")
				self.assertListEqual(_SCREAMING_SNAKE_CASE       ,			["你", "好", "[SEP]", "你", "是", "谁"])
				self.assertListEqual(tokenizer.convert_tokens_to_ids(_SCREAMING_SNAKE_CASE)       ,			[5, 6, 2, 5, 7, 8])
				self.assertListEqual(tokenizer.convert_tokens_to_shape_ids(_SCREAMING_SNAKE_CASE)       ,			[5, 6, 2, 5, 7, 8])
				self.assertListEqual(tokenizer.convert_tokens_to_pronunciation_ids(_SCREAMING_SNAKE_CASE)       ,			[5, 6, 2, 5, 7, 8])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       RoCBertBasicTokenizer()

				self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz")       ,			["ah", "\u535A", "\u63A8", "zz"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  ")       ,			["hello", "!", "how", "are", "you", "?"])
				self.assertListEqual(tokenizer.tokenize("H\u00E9llo")       ,			["hello"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE       ,			strip_accents=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")       ,			["hällo", "!", "how", "are", "you", "?"])
				self.assertListEqual(tokenizer.tokenize("H\u00E9llo")       ,			["h\u00E9llo"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE       ,			strip_accents=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")       ,			["hallo", "!", "how", "are", "you", "?"])
				self.assertListEqual(tokenizer.tokenize("H\u00E9llo")       ,			["hello"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")       ,			["hallo", "!", "how", "are", "you", "?"])
				self.assertListEqual(tokenizer.tokenize("H\u00E9llo")       ,			["hello"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  ")       ,			["HeLLo", "!", "how", "Are", "yoU", "?"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE       ,			strip_accents=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")       ,			["HäLLo", "!", "how", "Are", "yoU", "?"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE       ,			strip_accents=_SCREAMING_SNAKE_CASE)

				self.assertListEqual(
				    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")       ,			["HaLLo", "!", "how", "Are", "yoU", "?"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       RoCBertBasicTokenizer(do_lower_case=_SCREAMING_SNAKE_CASE       ,			never_split=["[UNK]"])

				self.assertListEqual(
				    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]")       ,			["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

				__lowerCAmelCase      :  Optional[int]												=       {}
				for i, token in enumerate(_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase      :  Optional[Any]												=       i
				__lowerCAmelCase      :  int												=       RoCBertWordpieceTokenizer(vocab=_SCREAMING_SNAKE_CASE       ,			unk_token="[UNK]")

				self.assertListEqual(tokenizer.tokenize("")       ,			[])

				self.assertListEqual(tokenizer.tokenize("unwanted running")       ,			["un", "##want", "##ed", "runn", "##ing"])

				self.assertListEqual(tokenizer.tokenize("unwantedX running")       ,			["[UNK]", "runn", "##ing"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Optional[int]:

				"""simple docstring"""

				self.assertTrue(_is_whitespace(" "))
				self.assertTrue(_is_whitespace("\t"))
				self.assertTrue(_is_whitespace("\r"))
				self.assertTrue(_is_whitespace("\n"))
				self.assertTrue(_is_whitespace("\u00A0"))

				self.assertFalse(_is_whitespace("A"))
				self.assertFalse(_is_whitespace("-"))

	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       Optional[Any]:

				"""simple docstring"""

				self.assertTrue(_is_control("\u0005"))

				self.assertFalse(_is_control("A"))
				self.assertFalse(_is_control(" "))
				self.assertFalse(_is_control("\t"))
				self.assertFalse(_is_control("\r"))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Dict:

				"""simple docstring"""

				self.assertTrue(_is_punctuation("-"))
				self.assertTrue(_is_punctuation("$"))
				self.assertTrue(_is_punctuation("`"))
				self.assertTrue(_is_punctuation("."))

				self.assertFalse(_is_punctuation("A"))
				self.assertFalse(_is_punctuation(" "))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       self.get_tokenizer()

				# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
				self.assertListEqual([tokenizer.tokenize(_SCREAMING_SNAKE_CASE) for t in ["Test", "\xad", "test"]]       ,			[["[UNK]"], [], ["[UNK]"]])

				if self.test_rust_tokenizer:
							__lowerCAmelCase      :  List[Any]												=       self.get_rust_tokenizer()
							self.assertListEqual(
							    [rust_tokenizer.tokenize(_SCREAMING_SNAKE_CASE) for t in ["Test", "\xad", "test"]]       ,			[["[UNK]"], [], ["[UNK]"]])

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       int:

				"""simple docstring"""

				for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
							with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
										__lowerCAmelCase      :  List[str]												=       self.rust_tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Union[str, Any]												=       F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
										__lowerCAmelCase      :  List[str]												=       tokenizer_r.encode_plus(
										    _SCREAMING_SNAKE_CASE       ,			return_attention_mask=_SCREAMING_SNAKE_CASE       ,			return_token_type_ids=_SCREAMING_SNAKE_CASE       ,			return_offsets_mapping=_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE       ,			)

										__lowerCAmelCase      :  Optional[Any]												=       tokenizer_r.do_lower_case if hasattr(_SCREAMING_SNAKE_CASE       ,			"do_lower_case") else False
										__lowerCAmelCase      :  Optional[int]												=       (
										    [
										        ((0, 0), tokenizer_r.cls_token),
										        ((0, 1), "A"),
										        ((1, 2), ","),
										        ((3, 5), "na"),
										        ((5, 6), "##ï"),
										        ((6, 8), "##ve"),
										        ((9, 15), tokenizer_r.mask_token),
										        ((16, 21), "Allen"),
										        ((21, 23), "##NL"),
										        ((23, 24), "##P"),
										        ((25, 33), "sentence"),
										        ((33, 34), "."),
										        ((0, 0), tokenizer_r.sep_token),
										    ]
										    if not do_lower_case
										    else [
										        ((0, 0), tokenizer_r.cls_token),
										        ((0, 1), "a"),
										        ((1, 2), ","),
										        ((3, 8), "naive"),
										        ((9, 15), tokenizer_r.mask_token),
										        ((16, 21), "allen"),
										        ((21, 23), "##nl"),
										        ((23, 24), "##p"),
										        ((25, 33), "sentence"),
										        ((33, 34), "."),
										        ((0, 0), tokenizer_r.sep_token),
										    ]
										)

										self.assertEqual(
										    [e[1] for e in expected_results]       ,			tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]))
										self.assertEqual([e[0] for e in expected_results]       ,			tokens["offset_mapping"])

	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       ["的", "人", "有"]
				__lowerCAmelCase      :  Tuple												=       "".join(_SCREAMING_SNAKE_CASE)
				for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
							with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
										__lowerCAmelCase      :  Tuple												=       True
										__lowerCAmelCase      :  List[Any]												=       self.tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Tuple												=       self.rust_tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Union[str, Any]												=       tokenizer_p.encode(_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Dict												=       tokenizer_r.encode(_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Any												=       tokenizer_r.convert_ids_to_tokens(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  List[Any]												=       tokenizer_p.convert_ids_to_tokens(_SCREAMING_SNAKE_CASE)

										# it is expected that each Chinese character is not preceded by "##"
										self.assertListEqual(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)
										self.assertListEqual(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  List[str]												=       False
										__lowerCAmelCase      :  int												=       self.rust_tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  str												=       self.tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Dict												=       tokenizer_r.encode(_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Optional[Any]												=       tokenizer_p.encode(_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Union[str, Any]												=       tokenizer_r.convert_ids_to_tokens(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Dict												=       tokenizer_p.convert_ids_to_tokens(_SCREAMING_SNAKE_CASE)

										# it is expected that only the first Chinese character is not preceded by "##".
										__lowerCAmelCase      :  List[str]												=       [
										    F"""##{token}""" if idx != 0 else token for idx, token in enumerate(_SCREAMING_SNAKE_CASE)
										]
										self.assertListEqual(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)
										self.assertListEqual(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)

	@slow
	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.tokenizer_class(self.vocab_file       ,			self.word_shape_file       ,			self.word_pronunciation_file)

				__lowerCAmelCase      :  List[str]												=       tokenizer.encode("你好"       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[int]												=       tokenizer.encode("你是谁"       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       tokenizer.build_inputs_with_special_tokens(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       tokenizer.build_inputs_with_special_tokens(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)

				assert encoded_sentence == [1] + text + [2]
				assert encoded_pair == [1] + text + [2] + text_a + [2]







	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.get_tokenizers(do_lower_case=_SCREAMING_SNAKE_CASE)
				for tokenizer in tokenizers:
							with self.subTest(F"""{tokenizer.__class__.__name__}"""):
										__lowerCAmelCase      :  List[Any]												=       "你好，你是谁"
										__lowerCAmelCase      :  Optional[int]												=       tokenizer.tokenize(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Dict												=       tokenizer.convert_tokens_to_ids(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Tuple												=       tokenizer.convert_tokens_to_shape_ids(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  int												=       tokenizer.convert_tokens_to_pronunciation_ids(_SCREAMING_SNAKE_CASE)
										__lowerCAmelCase      :  Optional[int]												=       tokenizer.prepare_for_model(
										    _SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)

										__lowerCAmelCase      :  Union[str, Any]												=       tokenizer.encode_plus(_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE)

										self.assertEqual(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)




"""simple docstring"""






import unittest

from transformers import SqueezeBertConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, 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 (
	    SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    SqueezeBertForMaskedLM,
	    SqueezeBertForMultipleChoice,
	    SqueezeBertForQuestionAnswering,
	    SqueezeBertForSequenceClassification,
	    SqueezeBertForTokenClassification,
	    SqueezeBertModel,
	)



class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	def __init__(     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		List[str]=13       ,			_SCREAMING_SNAKE_CASE:		Tuple=7       ,			_SCREAMING_SNAKE_CASE:		int=True       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=True       ,			_SCREAMING_SNAKE_CASE:		str=False       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=True       ,			_SCREAMING_SNAKE_CASE:		int=99       ,			_SCREAMING_SNAKE_CASE:		int=32       ,			_SCREAMING_SNAKE_CASE:		List[str]=5       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=4       ,			_SCREAMING_SNAKE_CASE:		int=64       ,			_SCREAMING_SNAKE_CASE:		List[str]="gelu"       ,			_SCREAMING_SNAKE_CASE:		str=0.1       ,			_SCREAMING_SNAKE_CASE:		Any=0.1       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=512       ,			_SCREAMING_SNAKE_CASE:		Tuple=16       ,			_SCREAMING_SNAKE_CASE:		Any=2       ,			_SCREAMING_SNAKE_CASE:		List[str]=0.02       ,			_SCREAMING_SNAKE_CASE:		Tuple=3       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=4       ,			_SCREAMING_SNAKE_CASE:		int=None       ,			_SCREAMING_SNAKE_CASE:		int=2       ,			_SCREAMING_SNAKE_CASE:		str=2       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=2       ,			_SCREAMING_SNAKE_CASE:		List[Any]=2       ,			_SCREAMING_SNAKE_CASE:		int=4       ,			_SCREAMING_SNAKE_CASE:		List[str]=1       ,			)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       parent
				__lowerCAmelCase      :  Optional[Any]												=       batch_size
				__lowerCAmelCase      :  Union[str, Any]												=       seq_length
				__lowerCAmelCase      :  Optional[Any]												=       is_training
				__lowerCAmelCase      :  Optional[int]												=       use_input_mask
				__lowerCAmelCase      :  Dict												=       use_token_type_ids
				__lowerCAmelCase      :  Dict												=       use_labels
				__lowerCAmelCase      :  Dict												=       vocab_size
				__lowerCAmelCase      :  Tuple												=       hidden_size
				__lowerCAmelCase      :  List[Any]												=       num_hidden_layers
				__lowerCAmelCase      :  Union[str, Any]												=       num_attention_heads
				__lowerCAmelCase      :  Tuple												=       intermediate_size
				__lowerCAmelCase      :  List[Any]												=       hidden_act
				__lowerCAmelCase      :  Optional[Any]												=       hidden_dropout_prob
				__lowerCAmelCase      :  Optional[Any]												=       attention_probs_dropout_prob
				__lowerCAmelCase      :  Optional[int]												=       max_position_embeddings
				__lowerCAmelCase      :  Union[str, Any]												=       type_vocab_size
				__lowerCAmelCase      :  Optional[int]												=       type_sequence_label_size
				__lowerCAmelCase      :  Dict												=       initializer_range
				__lowerCAmelCase      :  Tuple												=       num_labels
				__lowerCAmelCase      :  Optional[Any]												=       num_choices
				__lowerCAmelCase      :  Union[str, Any]												=       scope
				__lowerCAmelCase      :  Optional[Any]												=       q_groups
				__lowerCAmelCase      :  Optional[int]												=       k_groups
				__lowerCAmelCase      :  Any												=       v_groups
				__lowerCAmelCase      :  int												=       post_attention_groups
				__lowerCAmelCase      :  List[str]												=       intermediate_groups
				__lowerCAmelCase      :  Optional[Any]												=       output_groups

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       ids_tensor([self.batch_size, self.seq_length]       ,			self.vocab_size)

				__lowerCAmelCase      :  Union[str, Any]												=       None
				if self.use_input_mask:
							__lowerCAmelCase      :  Tuple												=       random_attention_mask([self.batch_size, self.seq_length])

				__lowerCAmelCase      :  Optional[int]												=       None
				__lowerCAmelCase      :  List[Any]												=       None
				__lowerCAmelCase      :  str												=       None
				if self.use_labels:
							__lowerCAmelCase      :  Optional[int]												=       ids_tensor([self.batch_size]       ,			self.type_sequence_label_size)
							__lowerCAmelCase      :  str												=       ids_tensor([self.batch_size, self.seq_length]       ,			self.num_labels)
							__lowerCAmelCase      :  str												=       ids_tensor([self.batch_size]       ,			self.num_choices)

				__lowerCAmelCase      :  Any												=       self.get_config()

				return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       int:

				"""simple docstring"""

				return SqueezeBertConfig(
				    embedding_size=self.hidden_size       ,			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       ,			attention_probs_dropout_prob=self.hidden_dropout_prob       ,			attention_dropout=self.attention_probs_dropout_prob       ,			max_position_embeddings=self.max_position_embeddings       ,			initializer_range=self.initializer_range       ,			q_groups=self.q_groups       ,			k_groups=self.k_groups       ,			v_groups=self.v_groups       ,			post_attention_groups=self.post_attention_groups       ,			intermediate_groups=self.intermediate_groups       ,			output_groups=self.output_groups       ,			)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[str]       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		Tuple)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       SqueezeBertModel(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase      :  List[Any]												=       model(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       model(_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.last_hidden_state.shape       ,			(self.batch_size, self.seq_length, self.hidden_size))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		List[str]       ,			_SCREAMING_SNAKE_CASE:		str       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Tuple)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       SqueezeBertForMaskedLM(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase      :  Dict												=       model(_SCREAMING_SNAKE_CASE       ,			attention_mask=_SCREAMING_SNAKE_CASE       ,			labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.seq_length, self.vocab_size))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       SqueezeBertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase      :  Union[str, Any]												=       model(
				    _SCREAMING_SNAKE_CASE       ,			attention_mask=_SCREAMING_SNAKE_CASE       ,			start_positions=_SCREAMING_SNAKE_CASE       ,			end_positions=_SCREAMING_SNAKE_CASE)
				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))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		Tuple)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       self.num_labels
				__lowerCAmelCase      :  Union[str, Any]												=       SqueezeBertForSequenceClassification(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase      :  int												=       model(_SCREAMING_SNAKE_CASE       ,			attention_mask=_SCREAMING_SNAKE_CASE       ,			labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.num_labels))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Optional[int])				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.num_labels
				__lowerCAmelCase      :  Optional[int]												=       SqueezeBertForTokenClassification(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()

				__lowerCAmelCase      :  List[str]												=       model(_SCREAMING_SNAKE_CASE       ,			attention_mask=_SCREAMING_SNAKE_CASE       ,			labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.seq_length, self.num_labels))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		int)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       self.num_choices
				__lowerCAmelCase      :  str												=       SqueezeBertForMultipleChoice(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase      :  int												=       input_ids.unsqueeze(1).expand(-1       ,			self.num_choices       ,			-1).contiguous()
				__lowerCAmelCase      :  Union[str, Any]												=       input_mask.unsqueeze(1).expand(-1       ,			self.num_choices       ,			-1).contiguous()
				__lowerCAmelCase      :  str												=       model(
				    _SCREAMING_SNAKE_CASE       ,			attention_mask=_SCREAMING_SNAKE_CASE       ,			labels=_SCREAMING_SNAKE_CASE       ,			)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.num_choices))







	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       self.prepare_config_and_inputs()
				((__lowerCAmelCase)						,	(__lowerCAmelCase)						,	(__lowerCAmelCase)						,	(__lowerCAmelCase)						,	(__lowerCAmelCase)						,	(__lowerCAmelCase))      :  Union[str, Any]												=       config_and_inputs
				__lowerCAmelCase      :  int												=       {"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict






@require_torch
class 			A__   (  __SCREAMING_SNAKE_CASE  ,		__SCREAMING_SNAKE_CASE  ,		unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	(
	    (
	        SqueezeBertModel,
	        SqueezeBertForMaskedLM,
	        SqueezeBertForMultipleChoice,
	        SqueezeBertForQuestionAnswering,
	        SqueezeBertForSequenceClassification,
	        SqueezeBertForTokenClassification,
	    )
	    if is_torch_available()
	    else None
	)
	SCREAMING_SNAKE_CASE          =	(
	    {
	        'feature-extraction': SqueezeBertModel,
	        'fill-mask': SqueezeBertForMaskedLM,
	        'question-answering': SqueezeBertForQuestionAnswering,
	        'text-classification': SqueezeBertForSequenceClassification,
	        'token-classification': SqueezeBertForTokenClassification,
	        'zero-shot': SqueezeBertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	SCREAMING_SNAKE_CASE          =	False
	SCREAMING_SNAKE_CASE          =	True
	SCREAMING_SNAKE_CASE          =	False

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       SqueezeBertModelTester(self)
				__lowerCAmelCase      :  Optional[int]												=       ConfigTester(self       ,			config_class=_SCREAMING_SNAKE_CASE       ,			dim=37)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Tuple:

				"""simple docstring"""

				self.config_tester.run_common_tests()

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Any:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_model(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_for_masked_lm(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_for_question_answering(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_for_sequence_classification(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_for_token_classification(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_squeezebert_for_multiple_choice(*_SCREAMING_SNAKE_CASE)







	@slow
	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Dict:

				"""simple docstring"""

				for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__lowerCAmelCase      :  Optional[Any]												=       SqueezeBertModel.from_pretrained(_SCREAMING_SNAKE_CASE)
							self.assertIsNotNone(_SCREAMING_SNAKE_CASE)






@require_sentencepiece
@require_tokenizers
@require_torch
class 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	@slow
	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       SqueezeBertForSequenceClassification.from_pretrained("squeezebert/squeezebert-mnli")

				__lowerCAmelCase      :  List[Any]												=       torch.tensor([[1, 2_9414, 232, 328, 740, 1140, 1_2695, 69, 13, 1588, 2]])
				__lowerCAmelCase      :  List[Any]												=       model(_SCREAMING_SNAKE_CASE)[0]
				__lowerCAmelCase      :  Any												=       torch.Size((1, 3))
				self.assertEqual(output.shape       ,			_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Union[str, Any]												=       torch.tensor([[0.6401, -0.0349, -0.6041]])
				self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-4))