import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_electra import ElectraTokenizer


UpperCamelCase__    							= {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

UpperCamelCase__    							= {
    'vocab_file': {
        'google/electra-small-generator': (
            'https://huggingface.co/google/electra-small-generator/resolve/main/vocab.txt'
        ),
        'google/electra-base-generator': 'https://huggingface.co/google/electra-base-generator/resolve/main/vocab.txt',
        'google/electra-large-generator': (
            'https://huggingface.co/google/electra-large-generator/resolve/main/vocab.txt'
        ),
        'google/electra-small-discriminator': (
            'https://huggingface.co/google/electra-small-discriminator/resolve/main/vocab.txt'
        ),
        'google/electra-base-discriminator': (
            'https://huggingface.co/google/electra-base-discriminator/resolve/main/vocab.txt'
        ),
        'google/electra-large-discriminator': (
            'https://huggingface.co/google/electra-large-discriminator/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'google/electra-small-generator': (
            'https://huggingface.co/google/electra-small-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-base-generator': (
            'https://huggingface.co/google/electra-base-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-large-generator': (
            'https://huggingface.co/google/electra-large-generator/resolve/main/tokenizer.json'
        ),
        'google/electra-small-discriminator': (
            'https://huggingface.co/google/electra-small-discriminator/resolve/main/tokenizer.json'
        ),
        'google/electra-base-discriminator': (
            'https://huggingface.co/google/electra-base-discriminator/resolve/main/tokenizer.json'
        ),
        'google/electra-large-discriminator': (
            'https://huggingface.co/google/electra-large-discriminator/resolve/main/tokenizer.json'
        ),
    },
}

UpperCamelCase__    							= {
    'google/electra-small-generator': 5_1_2,
    'google/electra-base-generator': 5_1_2,
    'google/electra-large-generator': 5_1_2,
    'google/electra-small-discriminator': 5_1_2,
    'google/electra-base-discriminator': 5_1_2,
    'google/electra-large-discriminator': 5_1_2,
}

UpperCamelCase__    							= {
    'google/electra-small-generator': {'do_lower_case': True},
    'google/electra-base-generator': {'do_lower_case': True},
    'google/electra-large-generator': {'do_lower_case': True},
    'google/electra-small-discriminator': {'do_lower_case': True},
    'google/electra-base-discriminator': {'do_lower_case': True},
    'google/electra-large-discriminator': {'do_lower_case': True},
}





class 					A							(    UpperCAmelCase_					):
   __UpperCAmelCase			:			Optional[int]              =      VOCAB_FILES_NAMES
   __UpperCAmelCase			:			Any              =      PRETRAINED_VOCAB_FILES_MAP
   __UpperCAmelCase			:			Tuple              =      PRETRAINED_INIT_CONFIGURATION
   __UpperCAmelCase			:			str              =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __UpperCAmelCase			:			List[Any]              =      ElectraTokenizer


   def __init__(self					:						List[Any]	,  __UpperCAmelCase					:						int=None	,  __UpperCAmelCase					:						str=None	,  __UpperCAmelCase					:						Dict=True	,  __UpperCAmelCase					:						Union[str, Any]="[UNK]"	,  __UpperCAmelCase					:						str="[SEP]"	,  __UpperCAmelCase					:						int="[PAD]"	,  __UpperCAmelCase					:						List[str]="[CLS]"	,  __UpperCAmelCase					:						Tuple="[MASK]"	,  __UpperCAmelCase					:						str=True	,  __UpperCAmelCase					:						Tuple=None	,  **__UpperCAmelCase					:						Tuple	,  )						->    Union[str, Any]:
         """simple docstring"""



         super().__init__(
             __UpperCAmelCase	,  tokenizer_file=__UpperCAmelCase	,  do_lower_case=__UpperCAmelCase	,  unk_token=__UpperCAmelCase	,  sep_token=__UpperCAmelCase	,  pad_token=__UpperCAmelCase	,  cls_token=__UpperCAmelCase	,  mask_token=__UpperCAmelCase	,  tokenize_chinese_chars=__UpperCAmelCase	,  strip_accents=__UpperCAmelCase	,  **__UpperCAmelCase	,  )

         UpperCAmelCase__								=  json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
         if (
             normalizer_state.get("lowercase"	,  __UpperCAmelCase		) != do_lower_case
             or normalizer_state.get("strip_accents"	,  __UpperCAmelCase		) != strip_accents
             or normalizer_state.get("handle_chinese_chars"	,  __UpperCAmelCase		) != tokenize_chinese_chars
         ):
               UpperCAmelCase__								=  getattr(__UpperCAmelCase	,  normalizer_state.pop("type"		)		)
               UpperCAmelCase__								=  do_lower_case
               UpperCAmelCase__								=  strip_accents
               UpperCAmelCase__								=  tokenize_chinese_chars
               UpperCAmelCase__								=  normalizer_class(**__UpperCAmelCase		)

         UpperCAmelCase__								=  do_lower_case


   def       lowercase_				(self					:						str	,  __UpperCAmelCase					:						Any	,  __UpperCAmelCase					:						List[str]=None		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  [self.cls_token_id] + token_ids_a + [self.sep_token_id]

         if token_ids_a:
               output += token_ids_a + [self.sep_token_id]

         return output


   def       lowercase_				(self					:						Optional[Any]	,  __UpperCAmelCase					:						List[int]	,  __UpperCAmelCase					:						Optional[List[int]] = None		)						->    List[int]:
         """simple docstring"""



         UpperCAmelCase__								=  [self.sep_token_id]
         UpperCAmelCase__								=  [self.cls_token_id]
         if token_ids_a is None:
               return len(cls + token_ids_a + sep		) * [0]
         return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]





   def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Optional[str] = None		)						->    Tuple[str]:
         """simple docstring"""



         UpperCAmelCase__								=  self._tokenizer.model.save(__UpperCAmelCase	,  name=__UpperCAmelCase		)
         return tuple(__UpperCAmelCase		)




# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch

from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer
from .base import PipelineTool





class 					A							(    UpperCAmelCase_					):
   __UpperCAmelCase			:			List[Any]              =      'facebook/bart-large-mnli'
   __UpperCAmelCase			:			Optional[Any]              =      (
       'This is a tool that classifies an English text using provided labels. It takes two inputs: `text`, which '
       'should be the text to classify, and `labels`, which should be the list of labels to use for classification. '
       'It returns the most likely label in the list of provided `labels` for the input text.'
   )
   __UpperCAmelCase			:			Optional[int]              =      'text_classifier'
   __UpperCAmelCase			:			int              =      AutoTokenizer
   __UpperCAmelCase			:			Dict              =      AutoModelForSequenceClassification

   __UpperCAmelCase			:			int              =      ['text', ['text']]
   __UpperCAmelCase			:			Optional[int]              =      ['text']


   def       lowercase_				(self					:						List[Any]		)						->    List[str]:
         """simple docstring"""



         super().setup()
         UpperCAmelCase__								=  self.model.config
         UpperCAmelCase__								=  -1
         for idx, label in config.idalabel.items():
               if label.lower().startswith("entail"		):
                     UpperCAmelCase__								=  int(__UpperCAmelCase		)
         if self.entailment_id == -1:
               raise ValueError("Could not determine the entailment ID from the model config, please pass it at init."		)


   def       lowercase_				(self					:						Union[str, Any]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						int		)						->    Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  labels
         return self.pre_processor(
             [text] * len(__UpperCAmelCase		)	,  [f"""This example is {label}""" for label in labels]	,  return_tensors="pt"	,  padding="max_length"	,  )





   def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						Tuple		)						->    int:
         """simple docstring"""



         UpperCAmelCase__								=  outputs.logits
         UpperCAmelCase__								=  torch.argmax(logits[:, 2]		).item()
         return self._labels[label_id]



