


'''simple docstring'''



import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter





class      UpperCAmelCase_						(TensorFormatter[Mapping, np.ndarray, Mapping]						):





    """simple docstring"""






    def __init__(							self    ,  SCREAMING_SNAKE_CASE_=None    ,  **SCREAMING_SNAKE_CASE_			)       ->  Tuple:
         super().__init__(features=SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			Dict              =	np_array_kwargs







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Tuple:
         if isinstance(SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			):
              if column and all(
                  isinstance(SCREAMING_SNAKE_CASE_    ,  np.ndarray			) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column			):
                   return np.stack(SCREAMING_SNAKE_CASE_			)
              else:
                   # don't use np.array(column, dtype=object)
                   # since it fails in certain cases
                   # see https://stackoverflow.com/q/51005699
                   __lowerCamelCase     :			Optional[Any]              =	np.empty(len(SCREAMING_SNAKE_CASE_			)    ,  dtype=SCREAMING_SNAKE_CASE_			)
                   __lowerCamelCase     :			Tuple              =	column
                   return out
         return column







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  List[Any]:
         if isinstance(SCREAMING_SNAKE_CASE_    ,  (str, bytes, type(SCREAMING_SNAKE_CASE_			))			):
              return value
         elif isinstance(SCREAMING_SNAKE_CASE_    ,  (np.character, np.ndarray)			) and np.issubdtype(value.dtype    ,  np.character			):
              return value
         elif isinstance(SCREAMING_SNAKE_CASE_    ,  np.number			):
              return value

         __lowerCamelCase     :			Dict              =	{}

         if isinstance(SCREAMING_SNAKE_CASE_    ,  np.ndarray			) and np.issubdtype(value.dtype    ,  np.integer			):
              __lowerCamelCase     :			Tuple              =	{'dtype': np.intaa}
         elif isinstance(SCREAMING_SNAKE_CASE_    ,  np.ndarray			) and np.issubdtype(value.dtype    ,  np.floating			):
              __lowerCamelCase     :			List[str]              =	{'dtype': np.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
              import PIL.Image

              if isinstance(SCREAMING_SNAKE_CASE_    ,  PIL.Image.Image			):
                   return np.asarray(SCREAMING_SNAKE_CASE_    ,  **self.np_array_kwargs			)

         return np.asarray(SCREAMING_SNAKE_CASE_    ,  **{**default_dtype, **self.np_array_kwargs}			)







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Optional[int]:
         # support for torch, tf, jax etc.
         if config.TORCH_AVAILABLE and "torch" in sys.modules:
              import torch

              if isinstance(SCREAMING_SNAKE_CASE_    ,  torch.Tensor			):
                   return self._tensorize(data_struct.detach().cpu().numpy()[()]			)
         if hasattr(SCREAMING_SNAKE_CASE_    ,  '__array__'			) and not isinstance(SCREAMING_SNAKE_CASE_    ,  (np.ndarray, np.character, np.number)			):
              __lowerCamelCase     :			List[Any]              =	data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(SCREAMING_SNAKE_CASE_    ,  np.ndarray			):
              if data_struct.dtype == object:
                   return self._consolidate([self.recursive_tensorize(SCREAMING_SNAKE_CASE_			) for substruct in data_struct]			)
         if isinstance(SCREAMING_SNAKE_CASE_    ,  (list, tuple)			):
              return self._consolidate([self.recursive_tensorize(SCREAMING_SNAKE_CASE_			) for substruct in data_struct]			)
         return self._tensorize(SCREAMING_SNAKE_CASE_			)







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Optional[int]:
         return map_nested(self._recursive_tensorize    ,  SCREAMING_SNAKE_CASE_    ,  map_list=SCREAMING_SNAKE_CASE_			)







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Mapping:
         __lowerCamelCase     :			Optional[Any]              =	self.numpy_arrow_extractor().extract_row(SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			str              =	self.python_features_decoder.decode_row(SCREAMING_SNAKE_CASE_			)
         return self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  np.ndarray:
         __lowerCamelCase     :			str              =	self.numpy_arrow_extractor().extract_column(SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			str              =	self.python_features_decoder.decode_column(SCREAMING_SNAKE_CASE_    ,  pa_table.column_names[0]			)
         __lowerCamelCase     :			Optional[Any]              =	self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			Tuple              =	self._consolidate(SCREAMING_SNAKE_CASE_			)
         return column







    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Mapping:
         __lowerCamelCase     :			Optional[int]              =	self.numpy_arrow_extractor().extract_batch(SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			Tuple              =	self.python_features_decoder.decode_batch(SCREAMING_SNAKE_CASE_			)
         __lowerCamelCase     :			str              =	self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)
         for column_name in batch:
              __lowerCamelCase     :			Union[str, Any]              =	self._consolidate(batch[column_name]			)
         return batch





'''simple docstring'''



from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A__	:      Any				=						logging.get_logger(__name__)

A__	:      str				=						{
    """microsoft/prophetnet-large-uncased""": (
        """https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json"""
    ),
}





class      UpperCAmelCase_						(_UpperCAmelCase						):





    """simple docstring"""






    lowerCamelCase						:      Dict							  =    'prophetnet'
    lowerCamelCase						:      List[str]							  =    ['past_key_values']
    lowerCamelCase						:      List[str]							  =    {
        'num_attention_heads': 'num_encoder_attention_heads',
    }







    def __init__(							self    ,  SCREAMING_SNAKE_CASE_ = 0.1    ,  SCREAMING_SNAKE_CASE_ = "gelu"    ,  SCREAMING_SNAKE_CASE_ = 3_05_22    ,  SCREAMING_SNAKE_CASE_ = 10_24    ,  SCREAMING_SNAKE_CASE_ = 40_96    ,  SCREAMING_SNAKE_CASE_ = 12    ,  SCREAMING_SNAKE_CASE_ = 16    ,  SCREAMING_SNAKE_CASE_ = 40_96    ,  SCREAMING_SNAKE_CASE_ = 12    ,  SCREAMING_SNAKE_CASE_ = 16    ,  SCREAMING_SNAKE_CASE_ = 0.1    ,  SCREAMING_SNAKE_CASE_ = 0.1    ,  SCREAMING_SNAKE_CASE_ = 5_12    ,  SCREAMING_SNAKE_CASE_ = 0.0_2    ,  SCREAMING_SNAKE_CASE_ = True    ,  SCREAMING_SNAKE_CASE_ = True    ,  SCREAMING_SNAKE_CASE_ = 0    ,  SCREAMING_SNAKE_CASE_ = 2    ,  SCREAMING_SNAKE_CASE_ = 32    ,  SCREAMING_SNAKE_CASE_ = 1_28    ,  SCREAMING_SNAKE_CASE_ = False    ,  SCREAMING_SNAKE_CASE_ = 0.0    ,  SCREAMING_SNAKE_CASE_ = True    ,  SCREAMING_SNAKE_CASE_ = 0    ,  SCREAMING_SNAKE_CASE_ = 1    ,  SCREAMING_SNAKE_CASE_ = 2    ,  **SCREAMING_SNAKE_CASE_    ,  )       ->  List[Any]:
         __lowerCamelCase     :			List[Any]              =	vocab_size
         __lowerCamelCase     :			Union[str, Any]              =	hidden_size
         __lowerCamelCase     :			Tuple              =	encoder_ffn_dim
         __lowerCamelCase     :			Any              =	num_encoder_layers
         __lowerCamelCase     :			int              =	num_encoder_attention_heads
         __lowerCamelCase     :			Optional[Any]              =	decoder_ffn_dim
         __lowerCamelCase     :			str              =	num_decoder_layers
         __lowerCamelCase     :			int              =	num_decoder_attention_heads
         __lowerCamelCase     :			Union[str, Any]              =	max_position_embeddings
         __lowerCamelCase     :			Optional[Any]              =	init_std  # Normal(0, this parameter)
         __lowerCamelCase     :			Union[str, Any]              =	activation_function

         # parameters for prophetnet
         __lowerCamelCase     :			int              =	ngram
         __lowerCamelCase     :			Optional[int]              =	num_buckets
         __lowerCamelCase     :			str              =	relative_max_distance
         __lowerCamelCase     :			Optional[Any]              =	disable_ngram_loss
         __lowerCamelCase     :			str              =	eps

         # 3 Types of Dropout
         __lowerCamelCase     :			Optional[Any]              =	attention_dropout
         __lowerCamelCase     :			str              =	activation_dropout
         __lowerCamelCase     :			Optional[Any]              =	dropout

         __lowerCamelCase     :			Optional[Any]              =	use_cache

         super().__init__(
             pad_token_id=SCREAMING_SNAKE_CASE_    ,  bos_token_id=SCREAMING_SNAKE_CASE_    ,  eos_token_id=SCREAMING_SNAKE_CASE_    ,  is_encoder_decoder=SCREAMING_SNAKE_CASE_    ,  add_cross_attention=SCREAMING_SNAKE_CASE_    ,  decoder_start_token_id=SCREAMING_SNAKE_CASE_    ,  **SCREAMING_SNAKE_CASE_    ,  )







    @property
    def    lowercase_       (							self			)       ->  int:
         return self.num_encoder_layers + self.num_decoder_layers







    @num_hidden_layers.setter
    def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_			)       ->  Union[str, Any]:
         raise NotImplementedError(
             'This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'
             ' `num_decoder_layers`.'			)






