




from typing import List, Union

import numpy as np

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, logging
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, ChunkPipeline


__a          =			logging.get_logger(__name__)

class   __a(					_a       ):






    """simple docstring"""





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE  )			->		Tuple:
         if isinstance(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  ):
              UpperCAmelCase_      :							List[Any]       =      [label.strip() for label in labels.split(''','''  ) if label.strip()]
         return labels





    def __call__(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[str]:
         if len(_SCREAMING_SNAKE_CASE  ) == 0 or len(_SCREAMING_SNAKE_CASE  ) == 0:
              raise ValueError('''You must include at least one label and at least one sequence.'''  )
         if hypothesis_template.format(labels[0]  ) == hypothesis_template:
              raise ValueError(
                  (
                      '''The provided hypothesis_template "{}" was not able to be formatted with the target labels. '''
                      '''Make sure the passed template includes formatting syntax such as {{}} where the label should go.'''
                  ).format(_SCREAMING_SNAKE_CASE  )  )

         if isinstance(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  ):
              UpperCAmelCase_      :							Optional[Any]       =      [sequences]

         UpperCAmelCase_      :							Optional[Any]       =      []
         for sequence in sequences:
              sequence_pairs.extend([[sequence, hypothesis_template.format(_SCREAMING_SNAKE_CASE  )] for label in labels]  )

         return sequence_pairs, sequences


@add_end_docstrings(_a       )
class   __a(					_a       ):






    """simple docstring"""





    def __init__(				self       ,_SCREAMING_SNAKE_CASE=ZeroShotClassificationArgumentHandler()       ,*_SCREAMING_SNAKE_CASE       ,**_SCREAMING_SNAKE_CASE  )			->		int:
         UpperCAmelCase_      :							Union[str, Any]       =      args_parser
         super().__init__(*_SCREAMING_SNAKE_CASE       ,**_SCREAMING_SNAKE_CASE  )
         if self.entailment_id == -1:
              logger.warning(
                  '''Failed to determine \'entailment\' label id from the label2id mapping in the model config. Setting to '''
                  '''-1. Define a descriptive label2id mapping in the model config to ensure correct outputs.'''  )





    @property
    def 							a__				(				self  )			->		int:
         for label, ind in self.model.config.labelaid.items():
              if label.lower().startswith('''entail'''  ):
                   return ind
         return -1





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=True       ,_SCREAMING_SNAKE_CASE=TruncationStrategy.ONLY_FIRST       ,**_SCREAMING_SNAKE_CASE  )			->		List[Any]:
         UpperCAmelCase_      :							List[str]       =      self.framework
         if self.tokenizer.pad_token is None:
              # Override for tokenizers not supporting padding
              logger.error(
                  '''Tokenizer was not supporting padding necessary for zero-shot, attempting to use '''
                  ''' `pad_token=eos_token`'''  )
              UpperCAmelCase_      :							List[str]       =      self.tokenizer.eos_token
         try:
              UpperCAmelCase_      :							str       =      self.tokenizer(
                  _SCREAMING_SNAKE_CASE       ,add_special_tokens=_SCREAMING_SNAKE_CASE       ,return_tensors=_SCREAMING_SNAKE_CASE       ,padding=_SCREAMING_SNAKE_CASE       ,truncation=_SCREAMING_SNAKE_CASE       ,)
         except Exception as e:
              if "too short" in str(_SCREAMING_SNAKE_CASE  ):
                   # tokenizers might yell that we want to truncate
                   # to a value that is not even reached by the input.
                   # In that case we don't want to truncate.
                   # It seems there's not a really better way to catch that
                   # exception.

                   UpperCAmelCase_      :							str       =      self.tokenizer(
                       _SCREAMING_SNAKE_CASE       ,add_special_tokens=_SCREAMING_SNAKE_CASE       ,return_tensors=_SCREAMING_SNAKE_CASE       ,padding=_SCREAMING_SNAKE_CASE       ,truncation=TruncationStrategy.DO_NOT_TRUNCATE       ,)
              else:
                   raise e

         return inputs





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		Dict:
         if kwargs.get('''multi_class'''       ,_SCREAMING_SNAKE_CASE  ) is not None:
              UpperCAmelCase_      :							Dict       =      kwargs['''multi_class''']
              logger.warning(
                  '''The `multi_class` argument has been deprecated and renamed to `multi_label`. '''
                  '''`multi_class` will be removed in a future version of Transformers.'''  )
         UpperCAmelCase_      :							Any       =      {}
         if "candidate_labels" in kwargs:
              UpperCAmelCase_      :							Union[str, Any]       =      self._args_parser._parse_labels(kwargs['''candidate_labels''']  )
         if "hypothesis_template" in kwargs:
              UpperCAmelCase_      :							Union[str, Any]       =      kwargs['''hypothesis_template''']

         UpperCAmelCase_      :							Optional[int]       =      {}
         if "multi_label" in kwargs:
              UpperCAmelCase_      :							List[str]       =      kwargs['''multi_label''']
         return preprocess_params, {}, postprocess_params





    def __call__(				self       ,_SCREAMING_SNAKE_CASE       ,*_SCREAMING_SNAKE_CASE       ,**_SCREAMING_SNAKE_CASE       ,)			->		Dict:
         if len(_SCREAMING_SNAKE_CASE  ) == 0:
              pass
         elif len(_SCREAMING_SNAKE_CASE  ) == 1 and "candidate_labels" not in kwargs:
              UpperCAmelCase_      :							str       =      args[0]
         else:
              raise ValueError(f'''Unable to understand extra arguments {args}'''  )

         return super().__call__(_SCREAMING_SNAKE_CASE       ,**_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE=None       ,_SCREAMING_SNAKE_CASE="This example is {}."  )			->		List[Any]:
         UpperCAmelCase_,   UpperCAmelCase_      :							Union[str, Any]       =      self._args_parser(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )

         for i, (candidate_label, sequence_pair) in enumerate(zip(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )  ):
              UpperCAmelCase_      :							Tuple       =      self._parse_and_tokenize([sequence_pair]  )

              yield {
                  "candidate_label": candidate_label,
                  "sequence": sequences[0],
                  "is_last": i == len(_SCREAMING_SNAKE_CASE  ) - 1,
                  **model_input,
              }





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE  )			->		int:
         UpperCAmelCase_      :							Tuple       =      inputs['''candidate_label''']
         UpperCAmelCase_      :							str       =      inputs['''sequence''']
         UpperCAmelCase_      :							Union[str, Any]       =      {k: inputs[k] for k in self.tokenizer.model_input_names}
         UpperCAmelCase_      :							str       =      self.model(**_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Dict       =      {
             '''candidate_label''': candidate_label,
             '''sequence''': sequence,
             '''is_last''': inputs['''is_last'''],
             **outputs,
         }
         return model_outputs





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE=False  )			->		Any:
         UpperCAmelCase_      :							int       =      [outputs['''candidate_label'''] for outputs in model_outputs]
         UpperCAmelCase_      :							Dict       =      [outputs['''sequence'''] for outputs in model_outputs]
         UpperCAmelCase_      :							Optional[int]       =      np.concatenate([output['''logits'''].numpy() for output in model_outputs]  )
         UpperCAmelCase_      :							List[Any]       =      logits.shape[0]
         UpperCAmelCase_      :							List[str]       =      len(_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Optional[int]       =      N // n
         UpperCAmelCase_      :							List[str]       =      logits.reshape((num_sequences, n, -1)  )

         if multi_label or len(_SCREAMING_SNAKE_CASE  ) == 1:
              # softmax over the entailment vs. contradiction dim for each label independently
              UpperCAmelCase_      :							Optional[Any]       =      self.entailment_id
              UpperCAmelCase_      :							int       =      -1 if entailment_id == 0 else 0
              UpperCAmelCase_      :							str       =      reshaped_outputs[..., [contradiction_id, entailment_id]]
              UpperCAmelCase_      :							List[Any]       =      np.exp(_SCREAMING_SNAKE_CASE  ) / np.exp(_SCREAMING_SNAKE_CASE  ).sum(-1       ,keepdims=_SCREAMING_SNAKE_CASE  )
              UpperCAmelCase_      :							int       =      scores[..., 1]
         else:
              # softmax the "entailment" logits over all candidate labels
              UpperCAmelCase_      :							Optional[Any]       =      reshaped_outputs[..., self.entailment_id]
              UpperCAmelCase_      :							Union[str, Any]       =      np.exp(_SCREAMING_SNAKE_CASE  ) / np.exp(_SCREAMING_SNAKE_CASE  ).sum(-1       ,keepdims=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Optional[Any]       =      list(reversed(scores[0].argsort()  )  )
         return {
             "sequence": sequences[0],
             "labels": [candidate_labels[i] for i in top_inds],
             "scores": scores[0, top_inds].tolist(),
         }





from collections import defaultdict







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Optional[int]       =      first_str.lower().strip()
     UpperCAmelCase_      :							Any       =      second_str.lower().strip()

     # Remove whitespace
     UpperCAmelCase_      :							Any       =      first_str.replace(''' '''			,						''''''				)
     UpperCAmelCase_      :							int       =      second_str.replace(''' '''			,						''''''				)

     # Strings of different lengths are not anagrams
     if len(_lowercase				) != len(_lowercase				):
          return False

     # Default values for count should be 0
     UpperCAmelCase_      :							defaultdict[str, int]       =      defaultdict(_lowercase				)

     # For each character in input strings,
     # increment count in the corresponding
     for i in range(len(_lowercase				)				):
          count[first_str[i]] += 1
          count[second_str[i]] -= 1

     return all(_count == 0 for _count in count.values()				)


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

     testmod()
     __a          =			input('Enter the first string ').strip()
     __a          =			input('Enter the second string ').strip()

     __a          =			check_anagrams(input_a, input_b)
     print(F"""{input_a} and {input_b} are {"" if status else "not "}anagrams.""")