



'''simple docstring'''






import unittest
from pathlib import Path
from shutil import copyfile

from transformers import SPIECE_UNDERLINE, is_sentencepiece_available
from transformers.models.speech_to_text import SpeechaTextTokenizer
from transformers.models.speech_to_text.tokenization_speech_to_text import VOCAB_FILES_NAMES, save_json
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase:      Tuple		 =		get_tests_dir('fixtures/test_sentencepiece.model')

if is_sentencepiece_available():
     import sentencepiece as sp


lowerCAmelCase:      List[Any]		 =		5
lowerCAmelCase:      Optional[int]		 =		1_0

@require_sentencepiece
@require_tokenizers
class 							a__(      __a	,				unittest.TestCase			):
    lowercase__				=					SpeechaTextTokenizer
    lowercase__				=					False
    lowercase__				=					True







    def     lowercase_ (   self				:						List[Any]			):
      super().setUp()

      a		:      Any       =  sp.SentencePieceProcessor()
      spm_model.Load(snake_case__			)
      a		:      List[str]       =  ['<s>', '<pad>', '</s>', '<unk>']

      vocab += [spm_model.IdToPiece(id_			) for id_ in range(len(snake_case__			)			)]
      a		:      int       =  dict(zip(snake_case__		,    range(len(snake_case__			)			)			)			)

      a		:      Any       =  Path(self.tmpdirname			)
      save_json(snake_case__		,    save_dir / VOCAB_FILES_NAMES['vocab_file']			)
      if not (save_dir / VOCAB_FILES_NAMES["spm_file"]).exists():
        copyfile(snake_case__		,    save_dir / VOCAB_FILES_NAMES['spm_file']			)

      a		:      List[Any]       =  SpeechaTextTokenizer.from_pretrained(self.tmpdirname			)
      tokenizer.save_pretrained(self.tmpdirname			)







    def     lowercase_ (   self				:						str			):
      a		:      Union[str, Any]       =  '<pad>'
      a		:      Tuple       =  1

      self.assertEqual(self.get_tokenizer()._convert_token_to_id(snake_case__			)		,    snake_case__			)
      self.assertEqual(self.get_tokenizer()._convert_id_to_token(snake_case__			)		,    snake_case__			)







    def     lowercase_ (   self				:						Optional[Any]			):
      a		:      Union[str, Any]       =  list(self.get_tokenizer().get_vocab().keys()			)

      self.assertEqual(vocab_keys[0]		,    '<s>'			)
      self.assertEqual(vocab_keys[1]		,    '<pad>'			)
      self.assertEqual(vocab_keys[-1]		,    'j'			)
      self.assertEqual(len(snake_case__			)		,    10_01			)







    def     lowercase_ (   self				:						Dict			):
      self.assertEqual(self.get_tokenizer().vocab_size		,    10_01			)







    def     lowercase_ (   self				:						Dict			):
      a		:      Dict       =  SpeechaTextTokenizer.from_pretrained(self.tmpdirname			)

      a		:      Union[str, Any]       =  tokenizer.tokenize('This is a test'			)
      self.assertListEqual(snake_case__		,    ['▁This', '▁is', '▁a', '▁t', 'est']			)

      self.assertListEqual(
          tokenizer.convert_tokens_to_ids(snake_case__			)		,    [2_89, 50, 14, 1_74, 3_86]		,    )

      a		:      int       =  tokenizer.tokenize('I was born in 92000, and this is falsé.'			)
      self.assertListEqual(
          snake_case__		,    [SPIECE_UNDERLINE + 'I', SPIECE_UNDERLINE + 'was', SPIECE_UNDERLINE + 'b', 'or', 'n', SPIECE_UNDERLINE + 'in', SPIECE_UNDERLINE + '', '9', '2', '0', '0', '0', ',', SPIECE_UNDERLINE + 'and', SPIECE_UNDERLINE + 'this', SPIECE_UNDERLINE + 'is', SPIECE_UNDERLINE + 'f', 'al', 's', 'é', '.']		,    )
      a		:      int       =  tokenizer.convert_tokens_to_ids(snake_case__			)
      self.assertListEqual(snake_case__		,    [12, 25, 88, 59, 28, 23, 11, 4, 6_06, 3_51, 3_51, 3_51, 7, 16, 70, 50, 76, 84, 10, 4, 8]			)

      a		:      List[Any]       =  tokenizer.convert_ids_to_tokens(snake_case__			)
      self.assertListEqual(
          snake_case__		,    [SPIECE_UNDERLINE + 'I', SPIECE_UNDERLINE + 'was', SPIECE_UNDERLINE + 'b', 'or', 'n', SPIECE_UNDERLINE + 'in', SPIECE_UNDERLINE + '', '<unk>', '2', '0', '0', '0', ',', SPIECE_UNDERLINE + 'and', SPIECE_UNDERLINE + 'this', SPIECE_UNDERLINE + 'is', SPIECE_UNDERLINE + 'f', 'al', 's', '<unk>', '.']		,    )







    @slow
    def     lowercase_ (   self				:						Optional[Any]			):
      # fmt: off
      a		:      Optional[int]       =  {'input_ids': [[37_91, 7_97, 31, 11, 64, 7_97, 31, 24_29, 4_33, 12, 11_76, 12, 20, 7_86, 9_15, 1_42, 24_13, 2_40, 37, 32_38, 7_97, 31, 11, 35, 93, 9_15, 1_42, 24_13, 2_40, 37, 55_40, 5_67, 12_76, 93, 37, 6_10, 40, 62, 4_55, 6_57, 10_42, 1_23, 7_80, 1_77, 37, 3_09, 2_41, 12_98, 5_14, 20, 2_92, 27_37, 1_14, 24_69, 2_41, 85, 64, 3_02, 5_48, 5_28, 4_23, 4, 5_09, 4_06, 4_23, 37, 6_01, 4, 7_77, 3_02, 5_48, 5_28, 4_23, 2_84, 4, 33_88, 5_11, 4_59, 4, 35_55, 40, 3_21, 3_02, 7_05, 4, 33_88, 5_11, 5_83, 3_26, 5, 5, 5, 62, 33_10, 5_60, 1_77, 26_80, 2_17, 15_08, 32, 31, 8_53, 4_18, 64, 5_83, 5_11, 16_05, 62, 35, 93, 5_60, 1_77, 26_80, 2_17, 15_08, 15_21, 64, 5_83, 5_11, 5_19, 62, 20, 15_15, 7_64, 20, 1_49, 2_61, 56_25, 79_72, 20, 55_40, 5_67, 12_76, 93, 39_25, 16_75, 11, 15, 8_02, 79_72, 5_76, 2_17, 15_08, 11, 35, 93, 12_53, 24_41, 15, 2_89, 6_52, 31, 4_16, 3_21, 38_42, 1_15, 40, 9_11, 8, 4_76, 6_19, 4, 3_80, 1_42, 4_23, 3_35, 2_40, 35, 93, 2_64, 8, 11, 3_35, 5_69, 4_20, 1_63, 5, 2], [2_60, 5_48, 5_28, 4_23, 20, 4_51, 20, 26_81, 11_53, 34_34, 20, 55_40, 37, 5_67, 1_26, 12_53, 24_41, 33_76, 4_49, 2_10, 4_31, 15_63, 1_77, 7_67, 55_40, 11, 12_03, 4_72, 11, 29_53, 6_85, 2_85, 3_64, 7_06, 11_53, 20, 67_99, 20, 28_69, 20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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
      # fmt: on

      self.tokenizer_integration_test_util(
          expected_encoding=snake_case__		,    model_name='facebook/s2t-small-mustc-en-de-st'		,    revision='a14f04cf0776c02f62a8cb800cf7909e15ea23ad'		,    )

@require_sentencepiece
class 							a__(      unittest.TestCase			):
    lowercase__				=					'''valhalla/s2t_mustc_multilinguial_medium'''

    lowercase__				=					'''C\'est trop cool'''
    lowercase__				=					'''Esto es genial'''







    @classmethod
    def     lowercase_ (   cls				:						List[Any]			):
      a		:      Union[str, Any]       =  SpeechaTextTokenizer.from_pretrained(cls.checkpoint_name			)
      return cls







    def     lowercase_ (   self				:						Union[str, Any]			):
      self.assertEqual(self.tokenizer.lang_code_to_id['pt']		,    4			)
      self.assertEqual(self.tokenizer.lang_code_to_id['ru']		,    6			)
      self.assertEqual(self.tokenizer.lang_code_to_id['it']		,    9			)
      self.assertEqual(self.tokenizer.lang_code_to_id['de']		,    11			)







    def     lowercase_ (   self				:						List[Any]			):
      self.assertEqual(self.tokenizer.vocab_size		,    1_00_00			)







    def     lowercase_ (   self				:						Union[str, Any]			):
      self.assertIn(snake_case__		,    self.tokenizer.all_special_ids			)
      a		:      Union[str, Any]       =  [ES_CODE, 4, 16_01, 47, 76_47, 2]
      a		:      List[Any]       =  self.tokenizer.decode(snake_case__		,    skip_special_tokens=snake_case__			)
      a		:      Any       =  self.tokenizer.decode(generated_ids[1:]		,    skip_special_tokens=snake_case__			)
      self.assertEqual(snake_case__		,    snake_case__			)
      self.assertNotIn(self.tokenizer.eos_token		,    snake_case__			)







    def     lowercase_ (   self				:						Any			):
      a		:      List[Any]       =  'fr'
      a		:      Optional[int]       =  self.tokenizer(self.french_text			).input_ids
      self.assertEqual(encoded[0]		,    snake_case__			)
      self.assertEqual(encoded[-1]		,    self.tokenizer.eos_token_id			)







    def     lowercase_ (   self				:						Dict			):
      a		:      Union[str, Any]       =  'fr'
      self.assertListEqual(self.tokenizer.prefix_tokens		,    [FR_CODE]			)

      a		:      Tuple       =  'es'
      self.assertListEqual(self.tokenizer.prefix_tokens		,    [ES_CODE]			)










'''simple docstring'''






from typing import Dict, List, Optional, Union

import numpy as np

from .feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from .utils import PaddingStrategy, TensorType, is_tf_tensor, is_torch_tensor, logging, to_numpy


lowerCAmelCase:      int		 =		logging.get_logger(__name__)

class 							a__(      lowerCamelCase__			):







    def __init__(   self				:						Union[str, Any]		,    __snake_case				:						int		,    __snake_case				:						int		,    __snake_case				:						float		,    **__snake_case				:						Optional[int]			):
      a		:      Optional[Any]       =  feature_size
      a		:      Tuple       =  sampling_rate
      a		:      str       =  padding_value

      a		:      Any       =  kwargs.pop('padding_side'		,    'right'			)
      a		:      Tuple       =  kwargs.pop('return_attention_mask'		,    __snake_case			)

      super().__init__(**__snake_case			)







    def     lowercase_ (   self				:						Tuple		,    __snake_case				:						Union[
            BatchFeature,
            List[BatchFeature],
            Dict[str, BatchFeature],
            Dict[str, List[BatchFeature]],
            List[Dict[str, BatchFeature]],
        ]		,    __snake_case				:						Union[bool, str, PaddingStrategy] = True		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						bool = False		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						Optional[bool] = None		,    __snake_case				:						Optional[Union[str, TensorType]] = None		,    ):
      # If we have a list of dicts, let's convert it in a dict of lists
      # We do this to allow using this method as a collate_fn function in PyTorch Dataloader
      if isinstance(__snake_case		,    (list, tuple)			) and isinstance(processed_features[0]		,    (dict, BatchFeature)			):
        a		:      Union[str, Any]       =  {
            key: [example[key] for example in processed_features] for key in processed_features[0].keys()
        }

      # The model's main input name, usually `input_values`, has be passed for padding
      if self.model_input_names[0] not in processed_features:
        raise ValueError(
            'You should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature`'
            F""" to this method that includes {self.model_input_names[0]}, but you provided"""
            F""" {list(processed_features.keys()			)}"""			)

      a		:      Tuple       =  processed_features[self.model_input_names[0]]
      a		:      str       =  (
          return_attention_mask if return_attention_mask is not None else self.return_attention_mask
      )

      if len(__snake_case			) == 0:
        if return_attention_mask:
          a		:      Dict       =  []
        return processed_features

      # If we have PyTorch/TF tensors or lists as inputs, we cast them as Numpy arrays
      # and rebuild them afterwards if no return_tensors is specified
      # Note that we lose the specific device the tensor may be on for PyTorch

      a		:      Optional[int]       =  required_input[0]
      if isinstance(__snake_case		,    (list, tuple)			):
        # first_element might be an empty list/tuple in some edge cases so we grab the first non empty element.
        a		:      Dict       =  0
        while len(required_input[index]			) == 0:
          index += 1
        if index < len(__snake_case			):
          a		:      Tuple       =  required_input[index][0]

      if return_tensors is None:
        if is_tf_tensor(__snake_case			):
          a		:      Any       =  'tf'
        elif is_torch_tensor(__snake_case			):
          a		:      Optional[Any]       =  'pt'
        elif isinstance(__snake_case		,    (int, float, list, tuple, np.ndarray)			):
          a		:      List[Any]       =  'np'
        else:
          raise ValueError(
              F"""type of {first_element} unknown: {type(__snake_case			)}. """
              'Should be one of a python, numpy, pytorch or tensorflow object.'			)

      for key, value in processed_features.items():
        if isinstance(value[0]		,    (int, float)			):
          a		:      List[Any]       =  to_numpy(__snake_case			)
        else:
          a		:      Tuple       =  [to_numpy(__snake_case			) for v in value]

        # Convert padding_strategy in PaddingStrategy
      a		:      Any       =  self._get_padding_strategies(padding=__snake_case		,    max_length=__snake_case			)

      a		:      int       =  processed_features[self.model_input_names[0]]

      a		:      Dict       =  len(__snake_case			)
      if not all(len(__snake_case			) == batch_size for v in processed_features.values()			):
        raise ValueError('Some items in the output dictionary have a different batch size than others.'			)

      a		:      Optional[int]       =  []
      for i in range(__snake_case			):
        a		:      int       =  {k: v[i] for k, v in processed_features.items()}
        # truncation
        a		:      List[str]       =  self._truncate(
            __snake_case		,    max_length=__snake_case		,    pad_to_multiple_of=__snake_case		,    truncation=__snake_case		,    )
        truncated_inputs.append(__snake_case			)

      if padding_strategy == PaddingStrategy.LONGEST:
        # make sure that `max_length` cannot be longer than the longest truncated length
        a		:      List[str]       =  max(len(input_slice[self.model_input_names[0]]			) for input_slice in truncated_inputs			)
        a		:      Tuple       =  PaddingStrategy.MAX_LENGTH

      a		:      int       =  {}
      for i in range(__snake_case			):
        # padding
        a		:      int       =  self._pad(
            truncated_inputs[i]		,    max_length=__snake_case		,    padding_strategy=__snake_case		,    pad_to_multiple_of=__snake_case		,    return_attention_mask=__snake_case		,    )

        for key, value in outputs.items():
          if key not in batch_outputs:
            a		:      int       =  []
          if value.dtype is np.dtype(np.floataa			):
            a		:      List[str]       =  value.astype(np.floataa			)
          batch_outputs[key].append(__snake_case			)

      return BatchFeature(__snake_case		,    tensor_type=__snake_case			)







    def     lowercase_ (   self				:						List[str]		,    __snake_case				:						Union[Dict[str, np.ndarray], BatchFeature]		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						PaddingStrategy = PaddingStrategy.DO_NOT_PAD		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						Optional[bool] = None		,    ):
      a		:      List[str]       =  processed_features[self.model_input_names[0]]

      if padding_strategy == PaddingStrategy.LONGEST:
        a		:      Any       =  len(__snake_case			)

      if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
        a		:      Dict       =  ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of

      a		:      List[Any]       =  padding_strategy != PaddingStrategy.DO_NOT_PAD and len(__snake_case			) < max_length

      if return_attention_mask and "attention_mask" not in processed_features:
        a		:      Union[str, Any]       =  np.ones(len(__snake_case			)		,    dtype=np.intaa			)

      if needs_to_be_padded:
        a		:      Tuple       =  max_length - len(__snake_case			)
        if self.padding_side == "right":
          if return_attention_mask:
            a		:      Any       =  np.pad(
                processed_features['attention_mask']		,    (0, difference)			)
          a		:      Optional[Any]       =  ((0, difference), (0, 0)) if self.feature_size > 1 else (0, difference)
          a		:      Optional[int]       =  np.pad(
              __snake_case		,    __snake_case		,    'constant'		,    constant_values=self.padding_value			)
        elif self.padding_side == "left":
          if return_attention_mask:
            a		:      Optional[int]       =  np.pad(
                processed_features['attention_mask']		,    (difference, 0)			)
          a		:      Optional[Any]       =  ((difference, 0), (0, 0)) if self.feature_size > 1 else (difference, 0)
          a		:      List[Any]       =  np.pad(
              __snake_case		,    __snake_case		,    'constant'		,    constant_values=self.padding_value			)
        else:
          raise ValueError('Invalid padding strategy:' + str(self.padding_side			)			)

      return processed_features







    def     lowercase_ (   self				:						List[str]		,    __snake_case				:						Union[Dict[str, np.ndarray], BatchFeature]		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						Optional[int] = None		,    __snake_case				:						Optional[bool] = None		,    ):
      if not truncation:
        return processed_features
      elif truncation and max_length is None:
        raise ValueError('When setting ``truncation=True``, make sure that ``max_length`` is defined.'			)

      a		:      Dict       =  processed_features[self.model_input_names[0]]

      # find `max_length` that fits `pad_to_multiple_of`
      if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
        a		:      Optional[Any]       =  ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of

      a		:      str       =  len(__snake_case			) > max_length

      if needs_to_be_truncated:
        a		:      str       =  processed_features[self.model_input_names[0]][:max_length]
        if "attention_mask" in processed_features:
          a		:      List[str]       =  processed_features['attention_mask'][:max_length]

      return processed_features







    def     lowercase_ (   self				:						Dict		,    __snake_case				:						Optional[Any]=False		,    __snake_case				:						Optional[int]=None			):

      # Get padding strategy
      if padding is not False:
        if padding is True:
          a		:      Union[str, Any]       =  PaddingStrategy.LONGEST  # Default to pad to the longest sequence in the batch
        elif not isinstance(__snake_case		,    __snake_case			):
          a		:      List[Any]       =  PaddingStrategy(__snake_case			)
        elif isinstance(__snake_case		,    __snake_case			):
          a		:      List[str]       =  padding
      else:
        a		:      Dict       =  PaddingStrategy.DO_NOT_PAD

      # Set max length if needed
      if max_length is None:
        if padding_strategy == PaddingStrategy.MAX_LENGTH:
          raise ValueError(
              F"""When setting ``padding={PaddingStrategy.MAX_LENGTH}``, make sure that max_length is defined"""			)

        # Test if we have a padding value
      if padding_strategy != PaddingStrategy.DO_NOT_PAD and (self.padding_value is None):
        raise ValueError(
            'Asking to pad but the feature_extractor does not have a padding value. Please select a value to use'
            ' as `padding_value`. For example: `feature_extractor.padding_value = 0.0`.'			)

      return padding_strategy