






"""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 			lowerCAmelCase__			(    __magic_name__   ):
   SCREAMING_SNAKE_CASE_    ='''facebook/bart-large-mnli'''
   SCREAMING_SNAKE_CASE_    =(
       '''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.'''
   )
   SCREAMING_SNAKE_CASE_    ='''text_classifier'''
   SCREAMING_SNAKE_CASE_    =AutoTokenizer
   SCREAMING_SNAKE_CASE_    =AutoModelForSequenceClassification

   SCREAMING_SNAKE_CASE_    =['''text''', ['''text''']]
   SCREAMING_SNAKE_CASE_    =['''text''']
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        super().setup()
        UpperCAmelCase__						:    Tuple							=							self.model.config
        UpperCAmelCase__						:    Dict							=							-1
        for idx, label in config.idalabel.items():
             if label.lower().startswith("entail"							):
                  UpperCAmelCase__						:    List[Any]							=							int(snake_case__							)
        if self.entailment_id == -1:
             raise ValueError("Could not determine the entailment ID from the model config, please pass it at init."							)
   def       __a							(		self      :	Tuple							,			snake_case__      :	Union[str, Any]							,			snake_case__      :	str							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[Any]							=							labels
        return self.pre_processor(
            [text] * len(snake_case__							)							,			[f'This example is {label}' for label in labels]							,			return_tensors="pt"							,			padding="max_length"							,			)




   def       __a							(		self      :	Optional[int]							,			snake_case__      :	List[Any]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Optional[int]							=							outputs.logits
        UpperCAmelCase__						:    Any							=							torch.argmax(logits[:, 2]							).item()
        return self._labels[label_id]










"""simple docstring"""



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


_lowerCAmelCase	:	Any				=      logging.get_logger(__name__)

_lowerCAmelCase	:	Union[str, Any]				=      {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}




class 			lowerCAmelCase__			(    __magic_name__   ):
   SCREAMING_SNAKE_CASE_    ='''megatron-bert'''
   def __init__(		self      :	Tuple							,			snake_case__      :	List[Any]=2_9_0_5_6							,			snake_case__      :	Any=1_0_2_4							,			snake_case__      :	Tuple=2_4							,			snake_case__      :	Optional[Any]=1_6							,			snake_case__      :	List[str]=4_0_9_6							,			snake_case__      :	Union[str, Any]="gelu"							,			snake_case__      :	int=0.1							,			snake_case__      :	Dict=0.1							,			snake_case__      :	str=5_1_2							,			snake_case__      :	Optional[Any]=2							,			snake_case__      :	Any=0.02							,			snake_case__      :	Optional[Any]=1e-12							,			snake_case__      :	str=0							,			snake_case__      :	Optional[Any]="absolute"							,			snake_case__      :	Optional[Any]=True							,			**snake_case__      :	Any							,			):


        '''simple docstring'''
        super().__init__(pad_token_id=snake_case__							,			**snake_case__							)

        UpperCAmelCase__						:    Union[str, Any]							=							vocab_size
        UpperCAmelCase__						:    Union[str, Any]							=							hidden_size
        UpperCAmelCase__						:    Optional[Any]							=							num_hidden_layers
        UpperCAmelCase__						:    Tuple							=							num_attention_heads
        UpperCAmelCase__						:    List[Any]							=							hidden_act
        UpperCAmelCase__						:    Optional[int]							=							intermediate_size
        UpperCAmelCase__						:    Dict							=							hidden_dropout_prob
        UpperCAmelCase__						:    str							=							attention_probs_dropout_prob
        UpperCAmelCase__						:    str							=							max_position_embeddings
        UpperCAmelCase__						:    List[str]							=							type_vocab_size
        UpperCAmelCase__						:    Tuple							=							initializer_range
        UpperCAmelCase__						:    str							=							layer_norm_eps
        UpperCAmelCase__						:    List[Any]							=							position_embedding_type
        UpperCAmelCase__						:    Dict							=							use_cache


