






'''simple docstring'''





import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, 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 (
     FlaubertForMultipleChoice,
     FlaubertForQuestionAnswering,
     FlaubertForQuestionAnsweringSimple,
     FlaubertForSequenceClassification,
     FlaubertForTokenClassification,
     FlaubertModel,
     FlaubertWithLMHeadModel,
 )
 from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST







class 	_UpperCAmelCase  (  __lowercase		):




      """simple docstring"""



      def __init__(   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase=13    ,	_lowerCAmelCase=7    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=False    ,	_lowerCAmelCase=False    ,	_lowerCAmelCase=False    ,	_lowerCAmelCase=2    ,	_lowerCAmelCase=99    ,	_lowerCAmelCase=0    ,	_lowerCAmelCase=32    ,	_lowerCAmelCase=5    ,	_lowerCAmelCase=4    ,	_lowerCAmelCase=0.1    ,	_lowerCAmelCase=0.1    ,	_lowerCAmelCase=512    ,	_lowerCAmelCase=12    ,	_lowerCAmelCase=2    ,	_lowerCAmelCase=0.02    ,	_lowerCAmelCase=3    ,	_lowerCAmelCase=4    ,	_lowerCAmelCase="last"    ,	_lowerCAmelCase=None    ,	_lowerCAmelCase=None    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				parent
          lowerCAmelCase__   :Union[str, Any]      							=				batch_size
          lowerCAmelCase__   :Optional[Any]      							=				seq_length
          lowerCAmelCase__   :str      							=				is_training
          lowerCAmelCase__   :int      							=				use_input_lengths
          lowerCAmelCase__   :Optional[Any]      							=				use_token_type_ids
          lowerCAmelCase__   :Any      							=				use_labels
          lowerCAmelCase__   :Optional[Any]      							=				gelu_activation
          lowerCAmelCase__   :Union[str, Any]      							=				sinusoidal_embeddings
          lowerCAmelCase__   :str      							=				causal
          lowerCAmelCase__   :Optional[int]      							=				asm
          lowerCAmelCase__   :List[str]      							=				n_langs
          lowerCAmelCase__   :List[str]      							=				vocab_size
          lowerCAmelCase__   :Tuple      							=				n_special
          lowerCAmelCase__   :Optional[int]      							=				hidden_size
          lowerCAmelCase__   :Optional[int]      							=				num_hidden_layers
          lowerCAmelCase__   :Union[str, Any]      							=				num_attention_heads
          lowerCAmelCase__   :Optional[int]      							=				hidden_dropout_prob
          lowerCAmelCase__   :str      							=				attention_probs_dropout_prob
          lowerCAmelCase__   :Tuple      							=				max_position_embeddings
          lowerCAmelCase__   :Optional[int]      							=				type_vocab_size
          lowerCAmelCase__   :List[Any]      							=				type_sequence_label_size
          lowerCAmelCase__   :List[Any]      							=				initializer_range
          lowerCAmelCase__   :Tuple      							=				num_labels
          lowerCAmelCase__   :str      							=				num_choices
          lowerCAmelCase__   :Optional[Any]      							=				summary_type
          lowerCAmelCase__   :int      							=				use_proj
          lowerCAmelCase__   :int      							=				scope
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size		)
          lowerCAmelCase__   :str      							=				random_attention_mask([self.batch_size, self.seq_length]		)

          lowerCAmelCase__   :Dict      							=				None
          if self.use_input_lengths:
              lowerCAmelCase__   :Optional[int]      							=				(
                  ids_tensor([self.batch_size]    ,	vocab_size=2		) + self.seq_length - 2
              )  # small variation of seq_length

          lowerCAmelCase__   :Dict      							=				None
          if self.use_token_type_ids:
              lowerCAmelCase__   :List[Any]      							=				ids_tensor([self.batch_size, self.seq_length]    ,	self.n_langs		)

          lowerCAmelCase__   :Dict      							=				None
          lowerCAmelCase__   :Tuple      							=				None
          lowerCAmelCase__   :List[Any]      							=				None
          if self.use_labels:
              lowerCAmelCase__   :List[Any]      							=				ids_tensor([self.batch_size]    ,	self.type_sequence_label_size		)
              lowerCAmelCase__   :Tuple      							=				ids_tensor([self.batch_size, self.seq_length]    ,	self.num_labels		)
              lowerCAmelCase__   :Optional[int]      							=				ids_tensor([self.batch_size]    ,	2		).float()
              lowerCAmelCase__   :Union[str, Any]      							=				ids_tensor([self.batch_size]    ,	self.num_choices		)

          lowerCAmelCase__   :List[str]      							=				self.get_config()

          return (
              config,
              input_ids,
              token_type_ids,
              input_lengths,
              sequence_labels,
              token_labels,
              is_impossible_labels,
              choice_labels,
              input_mask,
          )
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return FlaubertConfig(
              vocab_size=self.vocab_size    ,	n_special=self.n_special    ,	emb_dim=self.hidden_size    ,	n_layers=self.num_hidden_layers    ,	n_heads=self.num_attention_heads    ,	dropout=self.hidden_dropout_prob    ,	attention_dropout=self.attention_probs_dropout_prob    ,	gelu_activation=self.gelu_activation    ,	sinusoidal_embeddings=self.sinusoidal_embeddings    ,	asm=self.asm    ,	causal=self.causal    ,	n_langs=self.n_langs    ,	max_position_embeddings=self.max_position_embeddings    ,	initializer_range=self.initializer_range    ,	summary_type=self.summary_type    ,	use_proj=self.use_proj    ,	)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				FlaubertModel(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          lowerCAmelCase__   :Optional[Any]      							=				model(_lowerCAmelCase    ,	lengths=_lowerCAmelCase    ,	langs=_lowerCAmelCase		)
          lowerCAmelCase__   :Any      							=				model(_lowerCAmelCase    ,	langs=_lowerCAmelCase		)
          lowerCAmelCase__   :Tuple      							=				model(_lowerCAmelCase		)
          self.parent.assertEqual(result.last_hidden_state.shape    ,	(self.batch_size, self.seq_length, self.hidden_size)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				FlaubertWithLMHeadModel(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()

          lowerCAmelCase__   :Any      							=				model(_lowerCAmelCase    ,	token_type_ids=_lowerCAmelCase    ,	labels=_lowerCAmelCase		)
          self.parent.assertEqual(result.loss.shape    ,	()		)
          self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.seq_length, self.vocab_size)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				FlaubertForQuestionAnsweringSimple(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()

          lowerCAmelCase__   :List[Any]      							=				model(_lowerCAmelCase		)

          lowerCAmelCase__   :Tuple      							=				model(_lowerCAmelCase    ,	start_positions=_lowerCAmelCase    ,	end_positions=_lowerCAmelCase		)
          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 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				FlaubertForQuestionAnswering(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()

          lowerCAmelCase__   :Any      							=				model(_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[Any]      							=				model(
              _lowerCAmelCase    ,	start_positions=_lowerCAmelCase    ,	end_positions=_lowerCAmelCase    ,	cls_index=_lowerCAmelCase    ,	is_impossible=_lowerCAmelCase    ,	p_mask=_lowerCAmelCase    ,	)

          lowerCAmelCase__   :Dict      							=				model(
              _lowerCAmelCase    ,	start_positions=_lowerCAmelCase    ,	end_positions=_lowerCAmelCase    ,	cls_index=_lowerCAmelCase    ,	is_impossible=_lowerCAmelCase    ,	)

          (lowerCAmelCase__		)   :Optional[int]      							=				result_with_labels.to_tuple()

          lowerCAmelCase__   :str      							=				model(_lowerCAmelCase    ,	start_positions=_lowerCAmelCase    ,	end_positions=_lowerCAmelCase		)

          (lowerCAmelCase__		)   :Optional[int]      							=				result_with_labels.to_tuple()

          self.parent.assertEqual(result_with_labels.loss.shape    ,	()		)
          self.parent.assertEqual(result.start_top_log_probs.shape    ,	(self.batch_size, model.config.start_n_top)		)
          self.parent.assertEqual(result.start_top_index.shape    ,	(self.batch_size, model.config.start_n_top)		)
          self.parent.assertEqual(
              result.end_top_log_probs.shape    ,	(self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
          self.parent.assertEqual(
              result.end_top_index.shape    ,	(self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
          self.parent.assertEqual(result.cls_logits.shape    ,	(self.batch_size,)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				FlaubertForSequenceClassification(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()

          lowerCAmelCase__   :Optional[Any]      							=				model(_lowerCAmelCase		)
          lowerCAmelCase__   :Optional[Any]      							=				model(_lowerCAmelCase    ,	labels=_lowerCAmelCase		)

          self.parent.assertEqual(result.loss.shape    ,	()		)
          self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.type_sequence_label_size)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				self.num_labels
          lowerCAmelCase__   :Optional[int]      							=				FlaubertForTokenClassification(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()

          lowerCAmelCase__   :Union[str, Any]      							=				model(_lowerCAmelCase    ,	attention_mask=_lowerCAmelCase    ,	labels=_lowerCAmelCase		)
          self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.seq_length, self.num_labels)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				self.num_choices
          lowerCAmelCase__   :Dict      							=				FlaubertForMultipleChoice(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          lowerCAmelCase__   :int      							=				input_ids.unsqueeze(1		).expand(-1    ,	self.num_choices    ,	-1		).contiguous()
          lowerCAmelCase__   :Optional[int]      							=				token_type_ids.unsqueeze(1		).expand(-1    ,	self.num_choices    ,	-1		).contiguous()
          lowerCAmelCase__   :List[str]      							=				input_mask.unsqueeze(1		).expand(-1    ,	self.num_choices    ,	-1		).contiguous()
          lowerCAmelCase__   :Union[str, Any]      							=				model(
              _lowerCAmelCase    ,	attention_mask=_lowerCAmelCase    ,	token_type_ids=_lowerCAmelCase    ,	labels=_lowerCAmelCase    ,	)
          self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.num_choices)		)



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				self.prepare_config_and_inputs()
          (
              lowerCAmelCase__		
          )   :Tuple      							=				config_and_inputs
          lowerCAmelCase__   :Optional[Any]      							=				{
              "input_ids": input_ids,
              "token_type_ids": token_type_ids,
              "lengths": input_lengths,
              "attention_mask": input_mask,
          }
          return config, inputs_dict







@require_torch
class 	_UpperCAmelCase  (  __lowercase				,							__lowercase				,							unittest.TestCase		):




      """simple docstring"""



      A          =    (
          (
              FlaubertModel,
              FlaubertWithLMHeadModel,
              FlaubertForQuestionAnswering,
              FlaubertForQuestionAnsweringSimple,
              FlaubertForSequenceClassification,
              FlaubertForTokenClassification,
              FlaubertForMultipleChoice,
          )
          if is_torch_available()
          else ()
      )
      A          =    (
          {
              '''feature-extraction''': FlaubertModel,
              '''fill-mask''': FlaubertWithLMHeadModel,
              '''question-answering''': FlaubertForQuestionAnsweringSimple,
              '''text-classification''': FlaubertForSequenceClassification,
              '''token-classification''': FlaubertForTokenClassification,
              '''zero-shot''': FlaubertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):



          '''simple docstring'''
          if (
              pipeline_test_casse_name == "QAPipelineTests"
              and tokenizer_name is not None
              and not tokenizer_name.endswith("Fast"		)
          ):
              # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
              # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
              # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
              return True

          return False
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase=False		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				super()._prepare_for_class(_lowerCAmelCase    ,	_lowerCAmelCase    ,	return_labels=_lowerCAmelCase		)

          if return_labels:
              if model_class.__name__ == "FlaubertForQuestionAnswering":
                  lowerCAmelCase__   :str      							=				torch.zeros(
                      self.model_tester.batch_size    ,	dtype=torch.long    ,	device=_lowerCAmelCase		)
                  lowerCAmelCase__   :Dict      							=				torch.zeros(
                      self.model_tester.batch_size    ,	dtype=torch.long    ,	device=_lowerCAmelCase		)

          return inputs_dict
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				FlaubertModelTester(self		)
          lowerCAmelCase__   :Optional[int]      							=				ConfigTester(self    ,	config_class=_lowerCAmelCase    ,	emb_dim=37		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          self.config_tester.run_common_tests()
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_model(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_lm_head(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_simple_qa(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_qa(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_sequence_classif(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_token_classif(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_multiple_choice(*_lowerCAmelCase		)
      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__   :List[Any]      							=				FlaubertModel.from_pretrained(_lowerCAmelCase		)
              self.assertIsNotNone(_lowerCAmelCase		)



      @slow
      @require_torch_gpu
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				self.model_tester.prepare_config_and_inputs_for_common()
          for model_class in self.all_model_classes:
              # FlauBertForMultipleChoice behaves incorrectly in JIT environments.
              if model_class == FlaubertForMultipleChoice:
                  return

              lowerCAmelCase__   :Optional[Any]      							=				True
              lowerCAmelCase__   :Any      							=				model_class(config=_lowerCAmelCase		)

              lowerCAmelCase__   :Tuple      							=				self._prepare_for_class(_lowerCAmelCase    ,	_lowerCAmelCase		)
              lowerCAmelCase__   :int      							=				torch.jit.trace(
                  _lowerCAmelCase    ,	(inputs_dict["input_ids"].to("cpu"		), inputs_dict["attention_mask"].to("cpu"		))		)

              with tempfile.TemporaryDirectory() as tmp:
                  torch.jit.save(_lowerCAmelCase    ,	os.path.join(_lowerCAmelCase    ,	"traced_model.pt"		)		)
                  lowerCAmelCase__   :Union[str, Any]      							=				torch.jit.load(os.path.join(_lowerCAmelCase    ,	"traced_model.pt"		)    ,	map_location=_lowerCAmelCase		)
                  loaded(inputs_dict["input_ids"].to(_lowerCAmelCase		)    ,	inputs_dict["attention_mask"].to(_lowerCAmelCase		)		)







@require_torch
class 	_UpperCAmelCase  (  unittest.TestCase		):




      """simple docstring"""



      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				FlaubertModel.from_pretrained("flaubert/flaubert_base_cased"		)
          lowerCAmelCase__   :Any      							=				torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]		)
          with torch.no_grad():
              lowerCAmelCase__   :Union[str, Any]      							=				model(_lowerCAmelCase		)[0]
          lowerCAmelCase__   :int      							=				torch.Size((1, 11, 768)		)
          self.assertEqual(output.shape    ,	_lowerCAmelCase		)
          lowerCAmelCase__   :Union[str, Any]      							=				torch.tensor(
              [[[-2.6251, -1.4298, -0.0227], [-2.8510, -1.6387, 0.2258], [-2.8114, -1.1832, -0.3066]]]		)

          self.assertTrue(torch.allclose(output[:, :3, :3]    ,	_lowerCAmelCase    ,	atol=1e-4		)		)











import unittest

from transformers import CamembertTokenizer, CamembertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.utils import is_torch_available

from ...test_tokenization_common import TokenizerTesterMixin


_a    :   List[Any]        =			get_tests_dir("""fixtures/test_sentencepiece.model""")
_a    :   Dict        =			get_tests_dir("""fixtures/test_sentencepiece_bpe.model""")

_a    :   Optional[Any]        =			"""pt""" if is_torch_available() else """tf"""







@require_sentencepiece
@require_tokenizers
class 	_UpperCAmelCase  (  _A				,							unittest.TestCase		):




      """simple docstring"""



      A          =    CamembertTokenizer
      A          =    CamembertTokenizerFast
      A          =    True
      A          =    True
      def 			snake_case_      (   self		):



          '''simple docstring'''
          super().setUp()

          # We have a SentencePiece fixture for testing
          lowerCAmelCase__   :List[str]      							=				CamembertTokenizer(_lowerCAmelCase		)
          tokenizer.save_pretrained(self.tmpdirname		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				"<pad>"
          lowerCAmelCase__   :Union[str, Any]      							=				1

          self.assertEqual(self.get_tokenizer()._convert_token_to_id(_lowerCAmelCase		)    ,	_lowerCAmelCase		)
          self.assertEqual(self.get_tokenizer()._convert_id_to_token(_lowerCAmelCase		)    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				list(self.get_tokenizer().get_vocab().keys()		)

          self.assertEqual(vocab_keys[0]    ,	"<s>NOTUSED"		)
          self.assertEqual(vocab_keys[1]    ,	"<pad>"		)
          self.assertEqual(vocab_keys[-1]    ,	"<mask>"		)
          self.assertEqual(len(_lowerCAmelCase		)    ,	1_004		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          self.assertEqual(self.get_tokenizer().vocab_size    ,	1_005		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				CamembertTokenizer(_lowerCAmelCase		)
          tokenizer.save_pretrained(self.tmpdirname		)
          lowerCAmelCase__   :Tuple      							=				CamembertTokenizerFast.from_pretrained(self.tmpdirname		)

          lowerCAmelCase__   :List[str]      							=				"I was born in 92000, and this is falsé."

          lowerCAmelCase__   :Any      							=				tokenizer.encode(_lowerCAmelCase		)
          lowerCAmelCase__   :Any      							=				rust_tokenizer.encode(_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :int      							=				tokenizer.encode(_lowerCAmelCase    ,	add_special_tokens=_lowerCAmelCase		)
          lowerCAmelCase__   :List[Any]      							=				rust_tokenizer.encode(_lowerCAmelCase    ,	add_special_tokens=_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          # <unk> tokens are not the same for `rust` than for `slow`.
          # Because spm gives back raw token instead of `unk` in EncodeAsPieces
          # tokens = tokenizer.tokenize(sequence)
          lowerCAmelCase__   :Union[str, Any]      							=				tokenizer.convert_ids_to_tokens(_lowerCAmelCase		)
          lowerCAmelCase__   :Optional[int]      							=				rust_tokenizer.tokenize(_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          if not self.test_rust_tokenizer:
              return

          lowerCAmelCase__   :Optional[Any]      							=				self.get_tokenizer()
          lowerCAmelCase__   :int      							=				self.get_rust_tokenizer()

          lowerCAmelCase__   :List[str]      							=				"I was born in 92000, and this is falsé."

          lowerCAmelCase__   :int      							=				tokenizer.tokenize(_lowerCAmelCase		)
          lowerCAmelCase__   :List[str]      							=				rust_tokenizer.tokenize(_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Union[str, Any]      							=				tokenizer.encode(_lowerCAmelCase    ,	add_special_tokens=_lowerCAmelCase		)
          lowerCAmelCase__   :Any      							=				rust_tokenizer.encode(_lowerCAmelCase    ,	add_special_tokens=_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Dict      							=				self.get_rust_tokenizer()
          lowerCAmelCase__   :Tuple      							=				tokenizer.encode(_lowerCAmelCase		)
          lowerCAmelCase__   :Any      							=				rust_tokenizer.encode(_lowerCAmelCase		)
          self.assertListEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)



      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          # fmt: off
          lowerCAmelCase__   :str      							=				{"input_ids": [[5, 54, 7_196, 297, 30, 23, 776, 18, 11, 3_215, 3_705, 8_252, 22, 3_164, 1_181, 2_116, 29, 16, 813, 25, 791, 3_314, 20, 3_446, 38, 27_575, 120, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [5, 468, 17, 11, 9_088, 20, 1_517, 8, 22_804, 18_818, 10, 38, 629, 607, 607, 142, 19, 7_196, 867, 56, 10_326, 24, 2_267, 20, 416, 5_072, 15_612, 233, 734, 7, 2_399, 27, 16, 3_015, 1_649, 7, 24, 20, 4_338, 2_399, 27, 13, 3_400, 14, 13, 6_189, 8, 930, 9, 6]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}  # noqa: E501
          # fmt: on

          # camembert is a french model. So we also use french texts.
          lowerCAmelCase__   :Tuple      							=				[
              "Le transformeur est un modèle d'apprentissage profond introduit en 2017, "
              "utilisé principalement dans le domaine du traitement automatique des langues (TAL).",
              "À l'instar des réseaux de neurones récurrents (RNN), les transformeurs sont conçus "
              "pour gérer des données séquentielles, telles que le langage naturel, pour des tâches "
              "telles que la traduction et la synthèse de texte.",
          ]

          self.tokenizer_integration_test_util(
              expected_encoding=_lowerCAmelCase    ,	model_name="camembert-base"    ,	revision="3a0641d9a1aeb7e848a74299e7e4c4bca216b4cf"    ,	sequences=_lowerCAmelCase    ,	)



