
'''simple docstring'''



from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_herbert import HerbertTokenizer


UpperCamelCase__      :		int       							=  logging.get_logger(__name__)

UpperCamelCase__      :		List[str]       							=  {"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

UpperCamelCase__      :		str       							=  {
    "vocab_file": {
        "allegro/herbert-base-cased": "https://huggingface.co/allegro/herbert-base-cased/resolve/main/vocab.json"
    },
    "merges_file": {
        "allegro/herbert-base-cased": "https://huggingface.co/allegro/herbert-base-cased/resolve/main/merges.txt"
    },
}

UpperCamelCase__      :		Optional[Any]       							=  {"allegro/herbert-base-cased": 514}
UpperCamelCase__      :		List[str]       							=  {}

class    _a				(_lowerCamelCase):





       """simple docstring"""




       SCREAMING_SNAKE_CASE      =  VOCAB_FILES_NAMES
       SCREAMING_SNAKE_CASE      =  PRETRAINED_VOCAB_FILES_MAP
       SCREAMING_SNAKE_CASE      =  PRETRAINED_INIT_CONFIGURATION
       SCREAMING_SNAKE_CASE      =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       SCREAMING_SNAKE_CASE      =  HerbertTokenizer






       def __init__(							self       ,							A__=None       ,							A__=None       ,							A__=None       ,							A__="<s>"       ,							A__="<unk>"       ,							A__="<pad>"       ,							A__="<mask>"       ,							A__="</s>"       ,							**A__       ,							)    ->			List[str]:
          super().__init__(
              A__       ,							A__       ,							tokenizer_file=A__       ,							cls_token=A__       ,							unk_token=A__       ,							pad_token=A__       ,							mask_token=A__       ,							sep_token=A__       ,							**A__       ,							)






       def        UpperCamelCase				(							self       ,							A__       ,							A__ = None      )    ->			List[int]:
          _SCREAMING_SNAKE_CASE      =				[self.cls_token_id]
          _SCREAMING_SNAKE_CASE      =				[self.sep_token_id]
          if token_ids_a is None:
             return cls + token_ids_a + sep

          return cls + token_ids_a + sep + token_ids_a + sep






       def        UpperCamelCase				(							self       ,							A__       ,							A__ = None       ,							A__ = False      )    ->			List[int]:
          if already_has_special_tokens:
             return super().get_special_tokens_mask(
                 token_ids_a=A__       ,							token_ids_a=A__       ,							already_has_special_tokens=A__      )

          if token_ids_a is None:
             return [1] + ([0] * len(A__      )) + [1]
          return [1] + ([0] * len(A__      )) + [1] + ([0] * len(A__      )) + [1]






       def        UpperCamelCase				(							self       ,							A__       ,							A__ = None      )    ->			List[int]:
          _SCREAMING_SNAKE_CASE      =				[self.sep_token_id]
          _SCREAMING_SNAKE_CASE      =				[self.cls_token_id]

          if token_ids_a is None:
             return len(cls + token_ids_a + sep      ) * [0]
          return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]






       def        UpperCamelCase				(							self       ,							A__       ,							A__ = None      )    ->			Tuple[str]:
          _SCREAMING_SNAKE_CASE      =				self._tokenizer.model.save(A__       ,							name=A__      )
          return tuple(A__      )








'''simple docstring'''



import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
     import jax.numpy as jnp

if is_tf_available():
     import tensorflow as tf

if is_torch_available():
     import torch

class    _a				(unittest.TestCase):





       """simple docstring"""




       def        UpperCamelCase				(							self      )    ->			Optional[Any]:
          _SCREAMING_SNAKE_CASE      =				{
              """task_specific_params""": {
                  """summarization""": {"""length_penalty""": 1.0, """max_length""": 1_28, """min_length""": 12, """num_beams""": 4},
                  """summarization_cnn""": {"""length_penalty""": 2.0, """max_length""": 1_42, """min_length""": 56, """num_beams""": 4},
                  """summarization_xsum""": {"""length_penalty""": 1.0, """max_length""": 62, """min_length""": 11, """num_beams""": 6},
              }
          }
          _SCREAMING_SNAKE_CASE      =				{
              """task_specific_params.summarization.length_penalty""": 1.0,
              """task_specific_params.summarization.max_length""": 1_28,
              """task_specific_params.summarization.min_length""": 12,
              """task_specific_params.summarization.num_beams""": 4,
              """task_specific_params.summarization_cnn.length_penalty""": 2.0,
              """task_specific_params.summarization_cnn.max_length""": 1_42,
              """task_specific_params.summarization_cnn.min_length""": 56,
              """task_specific_params.summarization_cnn.num_beams""": 4,
              """task_specific_params.summarization_xsum.length_penalty""": 1.0,
              """task_specific_params.summarization_xsum.max_length""": 62,
              """task_specific_params.summarization_xsum.min_length""": 11,
              """task_specific_params.summarization_xsum.num_beams""": 6,
          }

          self.assertEqual(flatten_dict(A__      )       ,							A__      )






       def        UpperCamelCase				(							self      )    ->			int:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          self.assertTrue(np.allclose(transpose(A__      )       ,							x.transpose()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          self.assertTrue(np.allclose(transpose(A__       ,							axes=(1, 2, 0)      )       ,							x.transpose((1, 2, 0)      )      )      )






       @require_torch
       def        UpperCamelCase				(							self      )    ->			Optional[Any]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(transpose(A__      )       ,							transpose(A__      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(transpose(A__       ,							axes=(1, 2, 0)      )       ,							transpose(A__       ,							axes=(1, 2, 0)      ).numpy()      )      )






       @require_tf
       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(transpose(A__      )       ,							transpose(A__      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(transpose(A__       ,							axes=(1, 2, 0)      )       ,							transpose(A__       ,							axes=(1, 2, 0)      ).numpy()      )      )






       @require_flax
       def        UpperCamelCase				(							self      )    ->			List[str]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(transpose(A__      )       ,							np.asarray(transpose(A__      )      )      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(transpose(A__       ,							axes=(1, 2, 0)      )       ,							np.asarray(transpose(A__       ,							axes=(1, 2, 0)      )      )      )      )






       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          self.assertTrue(np.allclose(reshape(A__       ,							(4, 3)      )       ,							np.reshape(A__       ,							(4, 3)      )      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          self.assertTrue(np.allclose(reshape(A__       ,							(12, 5)      )       ,							np.reshape(A__       ,							(12, 5)      )      )      )






       @require_torch
       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(4, 3)      )       ,							reshape(A__       ,							(4, 3)      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(12, 5)      )       ,							reshape(A__       ,							(12, 5)      ).numpy()      )      )






       @require_tf
       def        UpperCamelCase				(							self      )    ->			Tuple:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(4, 3)      )       ,							reshape(A__       ,							(4, 3)      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(12, 5)      )       ,							reshape(A__       ,							(12, 5)      ).numpy()      )      )






       @require_flax
       def        UpperCamelCase				(							self      )    ->			List[Any]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(4, 3)      )       ,							np.asarray(reshape(A__       ,							(4, 3)      )      )      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4       ,							5      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(reshape(A__       ,							(12, 5)      )       ,							np.asarray(reshape(A__       ,							(12, 5)      )      )      )      )






       def        UpperCamelCase				(							self      )    ->			Any:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							3       ,							4      )
          self.assertTrue(np.allclose(squeeze(A__      )       ,							np.squeeze(A__      )      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							4       ,							1       ,							5      )
          self.assertTrue(np.allclose(squeeze(A__       ,							axis=2      )       ,							np.squeeze(A__       ,							axis=2      )      )      )






       @require_torch
       def        UpperCamelCase				(							self      )    ->			Any:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(squeeze(A__      )       ,							squeeze(A__      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							4       ,							1       ,							5      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(squeeze(A__       ,							axis=2      )       ,							squeeze(A__       ,							axis=2      ).numpy()      )      )






       @require_tf
       def        UpperCamelCase				(							self      )    ->			List[str]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(squeeze(A__      )       ,							squeeze(A__      ).numpy()      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							4       ,							1       ,							5      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(squeeze(A__       ,							axis=2      )       ,							squeeze(A__       ,							axis=2      ).numpy()      )      )






       @require_flax
       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(squeeze(A__      )       ,							np.asarray(squeeze(A__      )      )      )      )

          _SCREAMING_SNAKE_CASE      =				np.random.randn(1       ,							4       ,							1       ,							5      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(squeeze(A__       ,							axis=2      )       ,							np.asarray(squeeze(A__       ,							axis=2      )      )      )      )






       def        UpperCamelCase				(							self      )    ->			Optional[Any]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          self.assertTrue(np.allclose(expand_dims(A__       ,							axis=1      )       ,							np.expand_dims(A__       ,							axis=1      )      )      )






       @require_torch
       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				torch.tensor(A__      )
          self.assertTrue(np.allclose(expand_dims(A__       ,							axis=1      )       ,							expand_dims(A__       ,							axis=1      ).numpy()      )      )






       @require_tf
       def        UpperCamelCase				(							self      )    ->			str:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				tf.constant(A__      )
          self.assertTrue(np.allclose(expand_dims(A__       ,							axis=1      )       ,							expand_dims(A__       ,							axis=1      ).numpy()      )      )






       @require_flax
       def        UpperCamelCase				(							self      )    ->			Any:
          _SCREAMING_SNAKE_CASE      =				np.random.randn(3       ,							4      )
          _SCREAMING_SNAKE_CASE      =				jnp.array(A__      )
          self.assertTrue(np.allclose(expand_dims(A__       ,							axis=1      )       ,							np.asarray(expand_dims(A__       ,							axis=1      )      )      )      )






