'''simple docstring'''






# 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 lowercase_       (		_UpperCamelCase			):







   """simple docstring"""

   __lowerCAmelCase         =   "facebook/bart-large-mnli"
   __lowerCAmelCase         =   (
       "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."
   )
   __lowerCAmelCase         =   "text_classifier"
   __lowerCAmelCase         =   AutoTokenizer
   __lowerCAmelCase         =   AutoModelForSequenceClassification

   __lowerCAmelCase         =   ["text", ["text"]]
   __lowerCAmelCase         =   ["text"]
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			str:
        super().setup()
        _A    		=  self.model.config
        _A    		=  -1
        for idx, label in config.idalabel.items():
             if label.lower().startswith('entail'     ):
                  _A    		=  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 	__UpperCAmelCase   (      self      :			List[str], UpperCamelCase__      :			Optional[Any], UpperCamelCase__      :			int     )  ->			Optional[Any]:
        _A    		=  labels
        return self.pre_processor(
            [text] * len(UpperCamelCase__     ), [f'This example is {label}' for label in labels], return_tensors='pt', padding='max_length', )

   def 	__UpperCAmelCase   (      self      :			int, UpperCamelCase__      :			int     )  ->			Dict:
        _A    		=  outputs.logits
        _A    		=  torch.argmax(logits[:, 2]     ).item()
        return self._labels[label_id]




'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_UpperCAmelCase    :     Optional[Any]         =       logging.get_logger(__name__)

_UpperCAmelCase    :     List[Any]         =       {
    '''andreasmadsen/efficient_mlm_m0.40''': (
        '''https://huggingface.co/andreasmadsen/efficient_mlm_m0.40/resolve/main/config.json'''
    ),
}







class lowercase_       (		_UpperCamelCase			):







   """simple docstring"""

   __lowerCAmelCase         =   "roberta-prelayernorm"
   def __init__(      self      :			Optional[int], UpperCamelCase__      :			List[Any]=5_02_65, UpperCamelCase__      :			int=7_68, UpperCamelCase__      :			str=12, UpperCamelCase__      :			Union[str, Any]=12, UpperCamelCase__      :			Tuple=30_72, UpperCamelCase__      :			Tuple="gelu", UpperCamelCase__      :			List[Any]=0.1, UpperCamelCase__      :			Union[str, Any]=0.1, UpperCamelCase__      :			Any=5_12, UpperCamelCase__      :			Union[str, Any]=2, UpperCamelCase__      :			Optional[Any]=0.02, UpperCamelCase__      :			str=1e-12, UpperCamelCase__      :			str=1, UpperCamelCase__      :			List[str]=0, UpperCamelCase__      :			Optional[int]=2, UpperCamelCase__      :			Optional[Any]="absolute", UpperCamelCase__      :			Optional[Any]=True, UpperCamelCase__      :			List[str]=None, **UpperCamelCase__      :			Any, )  ->			Dict:
        super().__init__(pad_token_id=UpperCamelCase__, bos_token_id=UpperCamelCase__, eos_token_id=UpperCamelCase__, **UpperCamelCase__     )

        _A    		=  vocab_size
        _A    		=  hidden_size
        _A    		=  num_hidden_layers
        _A    		=  num_attention_heads
        _A    		=  hidden_act
        _A    		=  intermediate_size
        _A    		=  hidden_dropout_prob
        _A    		=  attention_probs_dropout_prob
        _A    		=  max_position_embeddings
        _A    		=  type_vocab_size
        _A    		=  initializer_range
        _A    		=  layer_norm_eps
        _A    		=  position_embedding_type
        _A    		=  use_cache
        _A    		=  classifier_dropout







class lowercase_       (		_UpperCamelCase			):







   """simple docstring"""

   @property
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Mapping[str, Mapping[int, str]]:
        if self.task == "multiple-choice":
             _A    		=  {0: 'batch', 1: 'choice', 2: 'sequence'}
        else:
             _A    		=  {0: 'batch', 1: 'sequence'}
        return OrderedDict(
            [
                ('input_ids', dynamic_axis),
                ('attention_mask', dynamic_axis),
            ]     )



