
from typing import List, Optional

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


__lowerCAmelCase     :	Union[str, Any]       			=  logging.get_logger(__name__)

__lowerCAmelCase     :	Optional[Any]       			=  {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}




class 			UpperCAmelCase_     (					_A	):


  '''simple docstring'''







  a__       			=						"""autoformer"""
  a__       			=						{
      """hidden_size""": """d_model""",
      """num_attention_heads""": """encoder_attention_heads""",
      """num_hidden_layers""": """encoder_layers""",
  }
  def __init__(					self     :					Dict     ,				UpperCamelCase__     :					Optional[int] = None     ,				UpperCamelCase__     :					Optional[int] = None     ,				UpperCamelCase__     :					str = "student_t"     ,				UpperCamelCase__     :					str = "nll"     ,				UpperCamelCase__     :					int = 1     ,				UpperCamelCase__     :					List[int] = [1, 2, 3, 4, 5, 6, 7]     ,				UpperCamelCase__     :					bool = True     ,				UpperCamelCase__     :					int = 0     ,				UpperCamelCase__     :					int = 0     ,				UpperCamelCase__     :					int = 0     ,				UpperCamelCase__     :					int = 0     ,				UpperCamelCase__     :					Optional[List[int]] = None     ,				UpperCamelCase__     :					Optional[List[int]] = None     ,				UpperCamelCase__     :					int = 64     ,				UpperCamelCase__     :					int = 2     ,				UpperCamelCase__     :					int = 2     ,				UpperCamelCase__     :					int = 2     ,				UpperCamelCase__     :					int = 2     ,				UpperCamelCase__     :					int = 32     ,				UpperCamelCase__     :					int = 32     ,				UpperCamelCase__     :					str = "gelu"     ,				UpperCamelCase__     :					float = 0.1     ,				UpperCamelCase__     :					float = 0.1     ,				UpperCamelCase__     :					float = 0.1     ,				UpperCamelCase__     :					float = 0.1     ,				UpperCamelCase__     :					float = 0.1     ,				UpperCamelCase__     :					int = 100     ,				UpperCamelCase__     :					float = 0.02     ,				UpperCamelCase__     :					bool = True     ,				UpperCamelCase__     :					int=True     ,				UpperCamelCase__     :					int = 10     ,				UpperCamelCase__     :					int = 25     ,				UpperCamelCase__     :					int = 3     ,				**UpperCamelCase__     :					Optional[Any]     ,				)     ->      Dict:







    """simple docstring"""






    __magic_name__								=			prediction_length
    __magic_name__								=			context_length if context_length is not None else prediction_length
    __magic_name__								=			distribution_output
    __magic_name__								=			loss
    __magic_name__								=			input_size
    __magic_name__								=			num_time_features
    __magic_name__								=			lags_sequence
    __magic_name__								=			scaling
    __magic_name__								=			num_dynamic_real_features
    __magic_name__								=			num_static_real_features
    __magic_name__								=			num_static_categorical_features
    if cardinality is not None and num_static_categorical_features > 0:
      if len(UpperCamelCase__       ) != num_static_categorical_features:
        raise ValueError(
            """The cardinality should be a list of the same length as `num_static_categorical_features`"""       )
      __magic_name__								=			cardinality
    else:
      __magic_name__								=			[0]
    if embedding_dimension is not None and num_static_categorical_features > 0:
      if len(UpperCamelCase__       ) != num_static_categorical_features:
        raise ValueError(
            """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""       )
      __magic_name__								=			embedding_dimension
    else:
      __magic_name__								=			[min(50     ,				(cat + 1) // 2       ) for cat in self.cardinality]
    __magic_name__								=			num_parallel_samples

    # Transformer architecture configuration
    __magic_name__								=			input_size * len(self.lags_sequence       ) + self._number_of_features
    __magic_name__								=			d_model
    __magic_name__								=			encoder_attention_heads
    __magic_name__								=			decoder_attention_heads
    __magic_name__								=			encoder_ffn_dim
    __magic_name__								=			decoder_ffn_dim
    __magic_name__								=			encoder_layers
    __magic_name__								=			decoder_layers

    __magic_name__								=			dropout
    __magic_name__								=			attention_dropout
    __magic_name__								=			activation_dropout
    __magic_name__								=			encoder_layerdrop
    __magic_name__								=			decoder_layerdrop

    __magic_name__								=			activation_function
    __magic_name__								=			init_std

    __magic_name__								=			use_cache

    # Autoformer
    __magic_name__								=			label_length
    __magic_name__								=			moving_average
    __magic_name__								=			autocorrelation_factor

    super().__init__(is_encoder_decoder=UpperCamelCase__     ,				**UpperCamelCase__       )





  @property
  def 				_lowercase				(					self     :					int       )     ->      int:







    """simple docstring"""






    return (
        sum(self.embedding_dimension       )
        + self.num_dynamic_real_features
        + self.num_time_features
        + self.num_static_real_features
        + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
    )



import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
    import bsa
    from bsa import BeautifulSoup


__lowerCAmelCase     :	int       			=  logging.get_logger(__name__)




class 			UpperCAmelCase_     (					_A	):


  '''simple docstring'''







  def __init__(					self     :					Union[str, Any]     ,				**UpperCamelCase__     :					Union[str, Any]       )     ->      Union[str, Any]:







    """simple docstring"""






    requires_backends(self     ,				["""bs4"""]       )
    super().__init__(**UpperCamelCase__       )
  def 				_lowercase				(					self     :					Dict     ,				UpperCamelCase__     :					Union[str, Any]       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			[]
    __magic_name__								=			[]
    __magic_name__								=			element if element.name else element.parent
    for parent in child.parents:  # type: bs4.element.Tag
      __magic_name__								=			parent.find_all(child.name     ,				recursive=UpperCamelCase__       )
      xpath_tags.append(child.name       )
      xpath_subscripts.append(
          0 if 1 == len(UpperCamelCase__       ) else next(i for i, s in enumerate(UpperCamelCase__     ,				1       ) if s is child       )       )
      __magic_name__								=			parent
    xpath_tags.reverse()
    xpath_subscripts.reverse()
    return xpath_tags, xpath_subscripts
  def 				_lowercase				(					self     :					Union[str, Any]     ,				UpperCamelCase__     :					List[Any]       )     ->      str:







    """simple docstring"""






    __magic_name__								=			BeautifulSoup(UpperCamelCase__     ,				"""html.parser"""       )

    __magic_name__								=			[]
    __magic_name__								=			[]
    __magic_name__								=			[]

    for element in html_code.descendants:
      if type(UpperCamelCase__       ) == bsa.element.NavigableString:
        if type(element.parent       ) != bsa.element.Tag:
          continue

        __magic_name__								=			html.unescape(UpperCamelCase__       ).strip()
        if not text_in_this_tag:
          continue

        all_doc_strings.append(UpperCamelCase__       )

        __magic_name__	,       __magic_name__								=			self.xpath_soup(UpperCamelCase__       )
        stringaxtag_seq.append(UpperCamelCase__       )
        stringaxsubs_seq.append(UpperCamelCase__       )

    if len(UpperCamelCase__       ) != len(UpperCamelCase__       ):
      raise ValueError("""Number of doc strings and xtags does not correspond"""       )
    if len(UpperCamelCase__       ) != len(UpperCamelCase__       ):
      raise ValueError("""Number of doc strings and xsubs does not correspond"""       )

    return all_doc_strings, stringaxtag_seq, stringaxsubs_seq
  def 				_lowercase				(					self     :					List[Any]     ,				UpperCamelCase__     :					Dict     ,				UpperCamelCase__     :					List[Any]       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			""""""
    for tagname, subs in zip(UpperCamelCase__     ,				UpperCamelCase__       ):
      xpath += F'''/{tagname}'''
      if subs != 0:
        xpath += F'''[{subs}]'''
    return xpath





  def __call__(					self     :					str     ,				UpperCamelCase__     :					Tuple       )     ->      BatchFeature:







    """simple docstring"""






    __magic_name__								=			False

    # Check that strings has a valid type
    if isinstance(UpperCamelCase__     ,				UpperCamelCase__       ):
      __magic_name__								=			True
    elif isinstance(UpperCamelCase__     ,				(list, tuple)       ):
      if len(UpperCamelCase__       ) == 0 or isinstance(html_strings[0]     ,				UpperCamelCase__       ):
        __magic_name__								=			True

    if not valid_strings:
      raise ValueError(
          """HTML strings must of type `str`, `List[str]` (batch of examples), """
          F'''but is of type {type(UpperCamelCase__       )}.'''       )

    __magic_name__								=			bool(isinstance(UpperCamelCase__     ,				(list, tuple)       ) and (isinstance(html_strings[0]     ,				UpperCamelCase__       ))       )

    if not is_batched:
      __magic_name__								=			[html_strings]

    # Get nodes + xpaths
    __magic_name__								=			[]
    __magic_name__								=			[]
    for html_string in html_strings:
      __magic_name__	,       __magic_name__	,       __magic_name__								=			self.get_three_from_single(UpperCamelCase__       )
      nodes.append(UpperCamelCase__       )
      __magic_name__								=			[]
      for node, tag_list, sub_list in zip(UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__       ):
        __magic_name__								=			self.construct_xpath(UpperCamelCase__     ,				UpperCamelCase__       )
        xpath_strings.append(UpperCamelCase__       )
      xpaths.append(UpperCamelCase__       )

    # return as Dict
    __magic_name__								=			{"""nodes""": nodes, """xpaths""": xpaths}
    __magic_name__								=			BatchFeature(data=UpperCamelCase__     ,				tensor_type=UpperCamelCase__       )

    return encoded_inputs

