





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


lowercase_          =		get_tests_dir("""fixtures/test_sentencepiece.model""")

if is_sentencepiece_available():
      import sentencepiece as sp


lowercase_          =		5
lowercase_          =		10
@require_sentencepiece
@require_tokenizers
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase      ,     unittest.TestCase				):
   _UpperCamelCase   :		Dict			 =	SpeechaTextTokenizer
   _UpperCamelCase   :		Union[str, Any]			 =	False
   _UpperCamelCase   :		str			 =	True


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Dict:





     """simple docstring"""







     super().setUp()

     lowercase__           =  sp.SentencePieceProcessor()
     spm_model.Load(a	)
     lowercase__           =  ['<s>', '<pad>', '</s>', '<unk>']

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

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

     lowercase__           =  SpeechaTextTokenizer.from_pretrained(self.tmpdirname	)
     tokenizer.save_pretrained(self.tmpdirname	)


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





     """simple docstring"""







     lowercase__           =  '<pad>'
     lowercase__           =  1

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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]	)->       Tuple:





     """simple docstring"""







     lowercase__           =  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(a	)      ,					1_001	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       Tuple:





     """simple docstring"""







     self.assertEqual(self.get_tokenizer().vocab_size      ,					1_001	)


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





     """simple docstring"""







     lowercase__           =  SpeechaTextTokenizer.from_pretrained(self.tmpdirname	)

     lowercase__           =  tokenizer.tokenize('This is a test'	)
     self.assertListEqual(a      ,					['▁This', '▁is', '▁a', '▁t', 'est']	)

     self.assertListEqual(
         tokenizer.convert_tokens_to_ids(a	)      ,					[289, 50, 14, 174, 386]      ,					)

     lowercase__           =  tokenizer.tokenize('I was born in 92000, and this is falsé.'	)
     self.assertListEqual(
         a      ,					[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', 'é', '.']      ,					)
     lowercase__           =  tokenizer.convert_tokens_to_ids(a	)
     self.assertListEqual(a      ,					[12, 25, 88, 59, 28, 23, 11, 4, 606, 351, 351, 351, 7, 16, 70, 50, 76, 84, 10, 4, 8]	)

     lowercase__           =  tokenizer.convert_ids_to_tokens(a	)
     self.assertListEqual(
         a      ,					[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 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  {'input_ids': [[3_791, 797, 31, 11, 64, 797, 31, 2_429, 433, 12, 1_176, 12, 20, 786, 915, 142, 2_413, 240, 37, 3_238, 797, 31, 11, 35, 93, 915, 142, 2_413, 240, 37, 5_540, 567, 1_276, 93, 37, 610, 40, 62, 455, 657, 1_042, 123, 780, 177, 37, 309, 241, 1_298, 514, 20, 292, 2_737, 114, 2_469, 241, 85, 64, 302, 548, 528, 423, 4, 509, 406, 423, 37, 601, 4, 777, 302, 548, 528, 423, 284, 4, 3_388, 511, 459, 4, 3_555, 40, 321, 302, 705, 4, 3_388, 511, 583, 326, 5, 5, 5, 62, 3_310, 560, 177, 2_680, 217, 1_508, 32, 31, 853, 418, 64, 583, 511, 1_605, 62, 35, 93, 560, 177, 2_680, 217, 1_508, 1_521, 64, 583, 511, 519, 62, 20, 1_515, 764, 20, 149, 261, 5_625, 7_972, 20, 5_540, 567, 1_276, 93, 3_925, 1_675, 11, 15, 802, 7_972, 576, 217, 1_508, 11, 35, 93, 1_253, 2_441, 15, 289, 652, 31, 416, 321, 3_842, 115, 40, 911, 8, 476, 619, 4, 380, 142, 423, 335, 240, 35, 93, 264, 8, 11, 335, 569, 420, 163, 5, 2], [260, 548, 528, 423, 20, 451, 20, 2_681, 1_153, 3_434, 20, 5_540, 37, 567, 126, 1_253, 2_441, 3_376, 449, 210, 431, 1_563, 177, 767, 5_540, 11, 1_203, 472, 11, 2_953, 685, 285, 364, 706, 1_153, 20, 6_799, 20, 2_869, 20, 4_464, 126, 40, 2_429, 20, 1_040, 866, 2_664, 418, 20, 318, 20, 1_726, 186, 20, 265, 522, 35, 93, 2_191, 4_634, 20, 1_040, 12, 6_799, 15, 228, 2_356, 142, 31, 11, 5, 2, 1, 1, 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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=a      ,					model_name='facebook/s2t-small-mustc-en-de-st'      ,					revision='a14f04cf0776c02f62a8cb800cf7909e15ea23ad'      ,					)






@require_sentencepiece
class     SCREAMING_SNAKE_CASE       (unittest.TestCase				):
   _UpperCamelCase   :		Tuple			 =	'valhalla/s2t_mustc_multilinguial_medium'

   _UpperCamelCase   :		List[Any]			 =	'C\'est trop cool'
   _UpperCamelCase   :		Optional[Any]			 =	'Esto es genial'


   @classmethod
   def 	SCREAMING_SNAKE_CASE_							(   cls      :    Dict	)->       Optional[Any]:





     """simple docstring"""







     lowercase__           =  SpeechaTextTokenizer.from_pretrained(cls.checkpoint_name	)
     return cls


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





     """simple docstring"""







     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 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       List[Any]:





     """simple docstring"""







     self.assertEqual(self.tokenizer.vocab_size      ,					10_000	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       Dict:





     """simple docstring"""







     self.assertIn(a      ,					self.tokenizer.all_special_ids	)
     lowercase__           =  [ES_CODE, 4, 1_601, 47, 7_647, 2]
     lowercase__           =  self.tokenizer.decode(a      ,					skip_special_tokens=a	)
     lowercase__           =  self.tokenizer.decode(generated_ids[1:]      ,					skip_special_tokens=a	)
     self.assertEqual(a      ,					a	)
     self.assertNotIn(self.tokenizer.eos_token      ,					a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]	)->       Dict:





     """simple docstring"""







     lowercase__           =  'fr'
     lowercase__           =  self.tokenizer(self.french_text	).input_ids
     self.assertEqual(encoded[0]      ,					a	)
     self.assertEqual(encoded[-1]      ,					self.tokenizer.eos_token_id	)


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





     """simple docstring"""







     lowercase__           =  'fr'
     self.assertListEqual(self.tokenizer.prefix_tokens      ,					[FR_CODE]	)

     lowercase__           =  'es'
     self.assertListEqual(self.tokenizer.prefix_tokens      ,					[ES_CODE]	)









import math
from typing import Dict, Iterable, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    is_torch_available,
    is_torch_tensor,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_torch_available():
      import torch

if is_vision_available():
      import PIL


lowercase_          =		logging.get_logger(__name__)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       Tuple[int, int]:
  def constraint_to_multiple_of(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE=0		,						_SCREAMING_SNAKE_CASE=None		):
    lowercase__           =  round(val / multiple		) * multiple

    if max_val is not None and x > max_val:
      lowercase__           =  math.floor(val / multiple		) * multiple

    if x < min_val:
      lowercase__           =  math.ceil(val / multiple		) * multiple

    return x

  lowercase__           =  (output_size, output_size) if isinstance(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		) else output_size

  lowercase__      ,   lowercase__           =  get_image_size(_SCREAMING_SNAKE_CASE		)
  lowercase__      ,   lowercase__           =  output_size

  # determine new height and width
  lowercase__           =  output_height / input_height
  lowercase__           =  output_width / input_width

  if keep_aspect_ratio:
    # scale as little as possible
    if abs(1 - scale_width		) < abs(1 - scale_height		):
      # fit width
      lowercase__           =  scale_width
    else:
      # fit height
      lowercase__           =  scale_height

  lowercase__           =  constraint_to_multiple_of(scale_height * input_height		,						multiple=_SCREAMING_SNAKE_CASE		)
  lowercase__           =  constraint_to_multiple_of(scale_width * input_width		,						multiple=_SCREAMING_SNAKE_CASE		)

  return (new_height, new_width)


class     SCREAMING_SNAKE_CASE       (UpperCAmelCase				):
   _UpperCamelCase   :		Dict			 =	['pixel_values']


   def __init__(   self      :    Any      ,					a      :    bool = True      ,					a      :    Dict[str, int] = None      ,					a      :    PILImageResampling = PILImageResampling.BILINEAR      ,					a      :    bool = False      ,					a      :    int = 1      ,					a      :    bool = True      ,					a      :    Union[int, float] = 1 / 255      ,					a      :    bool = True      ,					a      :    Optional[Union[float, List[float]]] = None      ,					a      :    Optional[Union[float, List[float]]] = None      ,					**a      :    Tuple      ,					)->       None:





     """simple docstring"""







     super().__init__(**a	)
     lowercase__           =  size if size is not None else {'height': 384, 'width': 384}
     lowercase__           =  get_size_dict(a	)
     lowercase__           =  do_resize
     lowercase__           =  size
     lowercase__           =  keep_aspect_ratio
     lowercase__           =  ensure_multiple_of
     lowercase__           =  resample
     lowercase__           =  do_rescale
     lowercase__           =  rescale_factor
     lowercase__           =  do_normalize
     lowercase__           =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
     lowercase__           =  image_std if image_std is not None else IMAGENET_STANDARD_STD


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    np.ndarray      ,					a      :    Dict[str, int]      ,					a      :    bool = False      ,					a      :    int = 1      ,					a      :    PILImageResampling = PILImageResampling.BICUBIC      ,					a      :    Optional[Union[str, ChannelDimension]] = None      ,					**a      :    Optional[Any]      ,					)->       np.ndarray:





     """simple docstring"""







     lowercase__           =  get_size_dict(a	)
     if "height" not in size or "width" not in size:
       raise ValueError(f"""The size dictionary must contain the keys 'height' and 'width'. Got {size.keys()}"""	)
     lowercase__           =  get_resize_output_image_size(
         a      ,					output_size=(size['height'], size['width'])      ,					keep_aspect_ratio=a      ,					multiple=a      ,					)
     return resize(a      ,					size=a      ,					resample=a      ,					data_format=a      ,					**a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    np.ndarray      ,					a      :    Union[int, float]      ,					a      :    Optional[Union[str, ChannelDimension]] = None      ,					**a      :    Dict      ,					)->       str:





     """simple docstring"""







     return rescale(a      ,					scale=a      ,					data_format=a      ,					**a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]      ,					a      :    np.ndarray      ,					a      :    Union[float, List[float]]      ,					a      :    Union[float, List[float]]      ,					a      :    Optional[Union[str, ChannelDimension]] = None      ,					**a      :    Optional[int]      ,					)->       np.ndarray:





     """simple docstring"""







     return normalize(a      ,					mean=a      ,					std=a      ,					data_format=a      ,					**a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    int      ,					a      :    ImageInput      ,					a      :    bool = None      ,					a      :    int = None      ,					a      :    bool = None      ,					a      :    int = None      ,					a      :    PILImageResampling = None      ,					a      :    bool = None      ,					a      :    float = None      ,					a      :    bool = None      ,					a      :    Optional[Union[float, List[float]]] = None      ,					a      :    Optional[Union[float, List[float]]] = None      ,					a      :    Optional[Union[str, TensorType]] = None      ,					a      :    ChannelDimension = ChannelDimension.FIRST      ,					**a      :    str      ,					)->       PIL.Image.Image:





     """simple docstring"""







     lowercase__           =  do_resize if do_resize is not None else self.do_resize
     lowercase__           =  size if size is not None else self.size
     lowercase__           =  get_size_dict(a	)
     lowercase__           =  keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
     lowercase__           =  ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
     lowercase__           =  resample if resample is not None else self.resample
     lowercase__           =  do_rescale if do_rescale is not None else self.do_rescale
     lowercase__           =  rescale_factor if rescale_factor is not None else self.rescale_factor
     lowercase__           =  do_normalize if do_normalize is not None else self.do_normalize
     lowercase__           =  image_mean if image_mean is not None else self.image_mean
     lowercase__           =  image_std if image_std is not None else self.image_std

     lowercase__           =  make_list_of_images(a	)

     if not valid_images(a	):
       raise ValueError(
           'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
           'torch.Tensor, tf.Tensor or jax.ndarray.'	)

     if do_resize and size is None or resample is None:
       raise ValueError('Size and resample must be specified if do_resize is True.'	)

     if do_rescale and rescale_factor is None:
       raise ValueError('Rescale factor must be specified if do_rescale is True.'	)

     if do_normalize and (image_mean is None or image_std is None):
       raise ValueError('Image mean and std must be specified if do_normalize is True.'	)

     # All transformations expect numpy arrays.
     lowercase__           =  [to_numpy_array(a	) for image in images]

     if do_resize:
       lowercase__           =  [self.resize(image=a      ,					size=a      ,					resample=a	) for image in images]

     if do_rescale:
       lowercase__           =  [self.rescale(image=a      ,					scale=a	) for image in images]

     if do_normalize:
       lowercase__           =  [self.normalize(image=a      ,					mean=a      ,					std=a	) for image in images]

     lowercase__           =  [to_channel_dimension_format(a      ,					a	) for image in images]

     lowercase__           =  {'pixel_values': images}
     return BatchFeature(data=a      ,					tensor_type=a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    str      ,					a      :    List[Tuple] = None	)->       Optional[int]:





     """simple docstring"""







     lowercase__           =  outputs.logits

     # Resize logits and compute semantic segmentation maps
     if target_sizes is not None:
       if len(a	) != len(a	):
         raise ValueError(
             'Make sure that you pass in as many target sizes as the batch dimension of the logits'	)

       if is_torch_tensor(a	):
         lowercase__           =  target_sizes.numpy()

       lowercase__           =  []

       for idx in range(len(a	)	):
         lowercase__           =  torch.nn.functional.interpolate(
             logits[idx].unsqueeze(dim=0	)      ,					size=target_sizes[idx]      ,					mode='bilinear'      ,					align_corners=a	)
         lowercase__           =  resized_logits[0].argmax(dim=0	)
         semantic_segmentation.append(a	)
     else:
       lowercase__           =  logits.argmax(dim=1	)
       lowercase__           =  [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]	)]

     return semantic_segmentation


