






"""simple docstring"""






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


UpperCAmelCase_   : Tuple   			= get_tests_dir("""fixtures/test_sentencepiece.model""")
UpperCAmelCase_   : List[str]   			= get_tests_dir("""fixtures/test_sentencepiece_bpe.model""")

UpperCAmelCase_   : Optional[int]   			= """pt""" if is_torch_available() else """tf"""




@require_sentencepiece
@require_tokenizers
class 							lowerCAmelCase__				(			UpperCAmelCase__				,		unittest.TestCase ):






      '''simple docstring'''

      __UpperCamelCase	 =  CamembertTokenizer
      __UpperCamelCase	 =  CamembertTokenizerFast
      __UpperCamelCase	 =  True
      __UpperCamelCase	 =  True
      def _SCREAMING_SNAKE_CASE (						self     :  Optional[Any]):




          '''simple docstring'''


          super().setUp()

          # We have a SentencePiece fixture for testing
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		CamembertTokenizer(lowercase_)
          tokenizer.save_pretrained(self.tmpdirname)
      def _SCREAMING_SNAKE_CASE (						self     :  List[str]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Any    						=		'''<pad>'''
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		1

          self.assertEqual(self.get_tokenizer()._convert_token_to_id(lowercase_)						,	lowercase_)
          self.assertEqual(self.get_tokenizer()._convert_id_to_token(lowercase_)						,	lowercase_)
      def _SCREAMING_SNAKE_CASE (						self     :  Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[str]    						=		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(lowercase_)						,	1004)
      def _SCREAMING_SNAKE_CASE (						self     :  Optional[Any]):




          '''simple docstring'''


          self.assertEqual(self.get_tokenizer().vocab_size						,	1005)
      def _SCREAMING_SNAKE_CASE (						self     :  Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  int    						=		CamembertTokenizer(lowercase_)
          tokenizer.save_pretrained(self.tmpdirname)
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		CamembertTokenizerFast.from_pretrained(self.tmpdirname)

          SCREAMING_SNAKE_CASE_      :  Tuple    						=		'''I was born in 92000, and this is falsé.'''

          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		tokenizer.encode(lowercase_)
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		rust_tokenizer.encode(lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Any    						=		tokenizer.encode(lowercase_						,	add_special_tokens=lowercase_)
          SCREAMING_SNAKE_CASE_      :  Dict    						=		rust_tokenizer.encode(lowercase_						,	add_special_tokens=lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)

          # <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)
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		tokenizer.convert_ids_to_tokens(lowercase_)
          SCREAMING_SNAKE_CASE_      :  Any    						=		rust_tokenizer.tokenize(lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)
      def _SCREAMING_SNAKE_CASE (						self     :  int):




          '''simple docstring'''


          if not self.test_rust_tokenizer:
              return

          SCREAMING_SNAKE_CASE_      :  str    						=		self.get_tokenizer()
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		self.get_rust_tokenizer()

          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		'''I was born in 92000, and this is falsé.'''

          SCREAMING_SNAKE_CASE_      :  Any    						=		tokenizer.tokenize(lowercase_)
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		rust_tokenizer.tokenize(lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Any    						=		tokenizer.encode(lowercase_						,	add_special_tokens=lowercase_)
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		rust_tokenizer.encode(lowercase_						,	add_special_tokens=lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Tuple    						=		self.get_rust_tokenizer()
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		tokenizer.encode(lowercase_)
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		rust_tokenizer.encode(lowercase_)
          self.assertListEqual(lowercase_						,	lowercase_)



      @slow
      def _SCREAMING_SNAKE_CASE (						self     :  Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Any    						=		{'''input_ids''': [[5, 54, 7196, 297, 30, 23, 776, 18, 11, 3215, 3705, 8252, 22, 3164, 1181, 2116, 29, 16, 813, 25, 791, 3314, 20, 3446, 38, 27575, 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, 9088, 20, 1517, 8, 22804, 18818, 10, 38, 629, 607, 607, 142, 19, 7196, 867, 56, 10326, 24, 2267, 20, 416, 5072, 15612, 233, 734, 7, 2399, 27, 16, 3015, 1649, 7, 24, 20, 4338, 2399, 27, 13, 3400, 14, 13, 6189, 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.
          SCREAMING_SNAKE_CASE_      :  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=lowercase_						,	model_name='''camembert-base'''						,	revision='''3a0641d9a1aeb7e848a74299e7e4c4bca216b4cf'''						,	sequences=lowercase_						,	)










"""simple docstring"""






from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)


