



"""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__  (       SCREAMING_SNAKE_CASE ):







       '''simple docstring'''


       UpperCamelCase		=	'''facebook/bart-large-mnli'''
       UpperCamelCase		=	(
           '''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		=	'''text_classifier'''
       UpperCamelCase		=	AutoTokenizer
       UpperCamelCase		=	AutoModelForSequenceClassification

       UpperCamelCase		=	['''text''', ['''text''']]
       UpperCamelCase		=	['''text''']



       def 	lowercase__							(				self     :    List[str]       )					->		Optional[Any]:


             '''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     :    Dict						,							_UpperCAmelCase     :    Optional[Any]						,							_UpperCAmelCase     :    Tuple       )					->		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     :    Any						,							_UpperCAmelCase     :    Dict       )					->		int:


             '''simple docstring'''




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











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


_lowerCamelCase      							=   logging.get_logger(__name__)

_lowerCamelCase      							=   {
    'sayakpaul/vit-msn-base': 'https://huggingface.co/sayakpaul/vit-msn-base/resolve/main/config.json',
    # See all ViT MSN models at https://huggingface.co/models?filter=vit_msn
}







class       __A							(   lowerCamelCase__	):




      """simple docstring"""







      UpperCAmelCase__							=   """vit_msn"""


      def __init__(		self   ,				a__=768   ,				a__=12   ,				a__=12   ,				a__=3072   ,				a__="gelu"   ,				a__=0.0   ,				a__=0.0   ,				a__=0.02   ,				a__=1e-06   ,				a__=224   ,				a__=16   ,				a__=3   ,				a__=True   ,				**a__   ,				):



             """simple docstring"""





             super().__init__(**a__)

             _lowerCamelCase				:  Tuple						=		hidden_size
             _lowerCamelCase				:  str						=		num_hidden_layers
             _lowerCamelCase				:  int						=		num_attention_heads
             _lowerCamelCase				:  Optional[int]						=		intermediate_size
             _lowerCamelCase				:  Union[str, Any]						=		hidden_act
             _lowerCamelCase				:  str						=		hidden_dropout_prob
             _lowerCamelCase				:  List[Any]						=		attention_probs_dropout_prob
             _lowerCamelCase				:  Optional[int]						=		initializer_range
             _lowerCamelCase				:  Optional[Any]						=		layer_norm_eps
             _lowerCamelCase				:  Dict						=		image_size
             _lowerCamelCase				:  Tuple						=		patch_size
             _lowerCamelCase				:  List[str]						=		num_channels
             _lowerCamelCase				:  Optional[int]						=		qkv_bias

