






from typing import Any






def 				lowerCamelCase__      (    __lowerCamelCase			:     list  ,		__lowerCamelCase			:     list  ,		__lowerCamelCase			:     dict  ,		__lowerCamelCase			:     dict  ,		__lowerCamelCase			:     dict  ,		):
  _validation(
      __lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		)
  # Creates data structures and fill initial step
  __UpperCAmelCase							:	dict           =  {}
  __UpperCAmelCase							:	dict           =  {}
  for state in states_space:
    __UpperCAmelCase							:	Union[str, Any]           =  observations_space[0]
    __UpperCAmelCase							:	Tuple           =  (
        initial_probabilities[state] * emission_probabilities[state][observation]
    )
    __UpperCAmelCase							:	Union[str, Any]           =  None

  # Fills the data structure with the probabilities of
  # different transitions and pointers to previous states
  for o in range(1  ,		len(__lowerCamelCase		)		):
    __UpperCAmelCase							:	Union[str, Any]           =  observations_space[o]
    __UpperCAmelCase							:	Optional[int]           =  observations_space[o - 1]
    for state in states_space:
      # Calculates the argmax for probability function
      __UpperCAmelCase							:	Any           =  """"""
      __UpperCAmelCase							:	Dict           =  -1
      for k_state in states_space:
        __UpperCAmelCase							:	str           =  (
            probabilities[(k_state, prior_observation)]
            * transition_probabilities[k_state][state]
            * emission_probabilities[state][observation]
        )
        if probability > max_probability:
          __UpperCAmelCase							:	Optional[Any]           =  probability
          __UpperCAmelCase							:	Optional[Any]           =  k_state

            # Update probabilities and pointers dicts
      __UpperCAmelCase							:	Optional[int]           =  (
          probabilities[(arg_max, prior_observation)]
          * transition_probabilities[arg_max][state]
          * emission_probabilities[state][observation]
      )

      __UpperCAmelCase							:	str           =  arg_max

    # The final observation
  __UpperCAmelCase							:	str           =  observations_space[len(__lowerCamelCase		) - 1]

  # argmax for given final observation
  __UpperCAmelCase							:	str           =  """"""
  __UpperCAmelCase							:	Tuple           =  -1
  for k_state in states_space:
    __UpperCAmelCase							:	Tuple           =  probabilities[(k_state, final_observation)]
    if probability > max_probability:
      __UpperCAmelCase							:	Tuple           =  probability
      __UpperCAmelCase							:	Tuple           =  k_state
  __UpperCAmelCase							:	int           =  arg_max

  # Process pointers backwards
  __UpperCAmelCase							:	List[Any]           =  last_state
  __UpperCAmelCase							:	List[str]           =  []
  for o in range(len(__lowerCamelCase		) - 1  ,		-1  ,		-1		):
    result.append(__lowerCamelCase		)
    __UpperCAmelCase							:	int           =  pointers[previous, observations_space[o]]
  result.reverse()

  return result






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		):
  _validate_not_empty(
      __lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		)
  _validate_lists(__lowerCamelCase  ,		__lowerCamelCase		)
  _validate_dicts(
      __lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		):
  if not all(
      [
          observations_space,
          states_space,
          initial_probabilities,
          transition_probabilities,
          emission_probabilities,
      ]		):
    raise ValueError("""There's an empty parameter"""		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any		):
  _validate_list(__lowerCamelCase  ,		"""observations_space"""		)
  _validate_list(__lowerCamelCase  ,		"""states_space"""		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     str		):
  if not isinstance(_object  ,		__lowerCamelCase		):
    __UpperCAmelCase							:	Tuple           =  f"""{var_name} must be a list"""
    raise ValueError(__lowerCamelCase		)
  else:
    for x in _object:
      if not isinstance(__lowerCamelCase  ,		__lowerCamelCase		):
        __UpperCAmelCase							:	List[str]           =  f"""{var_name} must be a list of strings"""
        raise ValueError(__lowerCamelCase		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		__lowerCamelCase			:     Any  ,		):
  _validate_dict(__lowerCamelCase  ,		"""initial_probabilities"""  ,		__lowerCamelCase		)
  _validate_nested_dict(__lowerCamelCase  ,		"""transition_probabilities"""		)
  _validate_nested_dict(__lowerCamelCase  ,		"""emission_probabilities"""		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     str		):
  _validate_dict(_object  ,		__lowerCamelCase  ,		__lowerCamelCase		)
  for x in _object.values():
    _validate_dict(__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase  ,		__lowerCamelCase		)






def 				lowerCamelCase__      (    __lowerCamelCase			:     Any  ,		__lowerCamelCase			:     str  ,		__lowerCamelCase			:     type  ,		__lowerCamelCase			:     bool = False		):
  if not isinstance(_object  ,		__lowerCamelCase		):
    __UpperCAmelCase							:	List[str]           =  f"""{var_name} must be a dict"""
    raise ValueError(__lowerCamelCase		)
  if not all(isinstance(__lowerCamelCase  ,		__lowerCamelCase		) for x in _object		):
    __UpperCAmelCase							:	List[str]           =  f"""{var_name} all keys must be strings"""
    raise ValueError(__lowerCamelCase		)
  if not all(isinstance(__lowerCamelCase  ,		__lowerCamelCase		) for x in _object.values()		):
    __UpperCAmelCase							:	List[str]           =  """nested dictionary """ if nested else """"""
    __UpperCAmelCase							:	Union[str, Any]           =  f"""{var_name} {nested_text}all values must be {value_type.__name__}"""
    raise ValueError(__lowerCamelCase		)


if __name__ == "__main__":
       from doctest import testmod

       testmod()










import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin
class     a    ( lowercase__   ):



      """simple docstring"""


      a  : List[str]							       =	'MCTCTFeatureExtractor'
      a  : str							       =	'AutoTokenizer'
      def __init__(      self					:			Tuple		,      __lowercase					:			int		,      __lowercase					:			Dict					)							->      Any:
        super().__init__(__lowercase		,      __lowercase					)
        __UpperCAmelCase							:	Optional[Any]           =  self.feature_extractor
        __UpperCAmelCase							:	Optional[int]           =  False
      def __call__(      self					:			int		,      *__lowercase					:			Tuple		,      **__lowercase					:			Optional[int]					)							->      Union[str, Any]:
        # For backward compatibility
        if self._in_target_context_manager:
          return self.current_processor(*__lowercase		,      **__lowercase					)

        if "raw_speech" in kwargs:
          warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""					)
          __UpperCAmelCase							:	Dict           =  kwargs.pop("""raw_speech"""					)
        else:
          __UpperCAmelCase							:	Dict           =  kwargs.pop("""audio"""		,      __lowercase					)
        __UpperCAmelCase							:	List[str]           =  kwargs.pop("""sampling_rate"""		,      __lowercase					)
        __UpperCAmelCase							:	Tuple           =  kwargs.pop("""text"""		,      __lowercase					)
        if len(__lowercase					) > 0:
          __UpperCAmelCase							:	Tuple           =  args[0]
          __UpperCAmelCase							:	str           =  args[1:]

        if audio is None and text is None:
          raise ValueError("""You need to specify either an `audio` or `text` input to process."""					)

        if audio is not None:
          __UpperCAmelCase							:	Tuple           =  self.feature_extractor(__lowercase		,      *__lowercase		,      sampling_rate=__lowercase		,      **__lowercase					)
        if text is not None:
          __UpperCAmelCase							:	str           =  self.tokenizer(__lowercase		,      **__lowercase					)

        if text is None:
          return inputs
        elif audio is None:
          return encodings
        else:
          __UpperCAmelCase							:	Dict           =  encodings["""input_ids"""]
          return inputs
      def 	UpperCAmelCase      (      self					:			Optional[Any]		,      *__lowercase					:			List[Any]		,      **__lowercase					:			int					)							->      List[Any]:
        return self.tokenizer.batch_decode(*__lowercase		,      **__lowercase					)
      def 	UpperCAmelCase      (      self					:			Optional[int]		,      *__lowercase					:			Optional[Any]		,      **__lowercase					:			List[str]					)							->      int:
        # For backward compatibility
        if self._in_target_context_manager:
          return self.current_processor.pad(*__lowercase		,      **__lowercase					)

        __UpperCAmelCase							:	Optional[int]           =  kwargs.pop("""input_features"""		,      __lowercase					)
        __UpperCAmelCase							:	Optional[Any]           =  kwargs.pop("""labels"""		,      __lowercase					)
        if len(__lowercase					) > 0:
          __UpperCAmelCase							:	Union[str, Any]           =  args[0]
          __UpperCAmelCase							:	str           =  args[1:]

        if input_features is not None:
          __UpperCAmelCase							:	Any           =  self.feature_extractor.pad(__lowercase		,      *__lowercase		,      **__lowercase					)
        if labels is not None:
          __UpperCAmelCase							:	Union[str, Any]           =  self.tokenizer.pad(__lowercase		,      **__lowercase					)

        if labels is None:
          return input_features
        elif input_features is None:
          return labels
        else:
          __UpperCAmelCase							:	Any           =  labels["""input_ids"""]
          return input_features
      def 	UpperCAmelCase      (      self					:			Any		,      *__lowercase					:			Union[str, Any]		,      **__lowercase					:			Dict					)							->      List[Any]:
        return self.tokenizer.decode(*__lowercase		,      **__lowercase					)




      @contextmanager
      def 	UpperCAmelCase      (      self					:			Optional[Any]					)							->      Tuple:
        warnings.warn(
            """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
            """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
            """your audio inputs, or in a separate call."""					)
        __UpperCAmelCase							:	Any           =  True
        __UpperCAmelCase							:	Optional[int]           =  self.tokenizer
        yield
        __UpperCAmelCase							:	List[Any]           =  self.feature_extractor
        __UpperCAmelCase							:	int           =  False


