






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_a      	=  logging.get_logger(__name__)

_a      	=  {
    '''shi-labs/nat-mini-in1k-224''': '''https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json''',
    # See all Nat models at https://huggingface.co/models?filter=nat
}





class __lowerCamelCase (      snake_case__     ,       snake_case__):





	"""simple docstring"""






	UpperCamelCase__								=      "nat"

	UpperCamelCase__								=      {
	    "num_attention_heads": "num_heads",
	    "num_hidden_layers": "num_layers",
	}

	def __init__(							self       ,    UpperCAmelCase=4       ,    UpperCAmelCase=3       ,    UpperCAmelCase=64       ,    UpperCAmelCase=[3, 4, 6, 5]       ,    UpperCAmelCase=[2, 4, 8, 16]       ,    UpperCAmelCase=7       ,    UpperCAmelCase=3.0       ,    UpperCAmelCase=True       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=0.1       ,    UpperCAmelCase="gelu"       ,    UpperCAmelCase=0.02       ,    UpperCAmelCase=1e-5       ,    UpperCAmelCase=0.0       ,    UpperCAmelCase=None       ,    UpperCAmelCase=None       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							super().__init__(**UpperCAmelCase    )

							_UpperCAmelCase									=			patch_size
							_UpperCAmelCase									=			num_channels
							_UpperCAmelCase									=			embed_dim
							_UpperCAmelCase									=			depths
							_UpperCAmelCase									=			len(UpperCAmelCase    )
							_UpperCAmelCase									=			num_heads
							_UpperCAmelCase									=			kernel_size
							_UpperCAmelCase									=			mlp_ratio
							_UpperCAmelCase									=			qkv_bias
							_UpperCAmelCase									=			hidden_dropout_prob
							_UpperCAmelCase									=			attention_probs_dropout_prob
							_UpperCAmelCase									=			drop_path_rate
							_UpperCAmelCase									=			hidden_act
							_UpperCAmelCase									=			layer_norm_eps
							_UpperCAmelCase									=			initializer_range
							# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
							# this indicates the channel dimension after the last stage of the model
							_UpperCAmelCase									=			int(embed_dim * 2 ** (len(UpperCAmelCase    ) - 1)    )
							_UpperCAmelCase									=			layer_scale_init_value
							_UpperCAmelCase									=			['stem'] + [F"""stage{idx}""" for idx in range(1       ,    len(UpperCAmelCase    ) + 1    )]
							_UpperCAmelCase					, _UpperCAmelCase									=			get_aligned_output_features_output_indices(
							    out_features=UpperCAmelCase       ,    out_indices=UpperCAmelCase       ,    stage_names=self.stage_names    )

# 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_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						Optional[Any]						=      """facebook/bart-large-mnli"""
    a__	:						int						=      (
        """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."""
    )
    a__	:						Optional[Any]						=      """text_classifier"""
    a__	:						Any						=      AutoTokenizer
    a__	:						str						=      AutoModelForSequenceClassification

    a__	:						str						=      ["""text""", ["""text"""]]
    a__	:						Optional[int]						=      ["""text"""]







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







    def 			UpperCamelCase__   (	self , __lowercase)       ->	Optional[Any]:
        __UpperCamelCase     :List[Any]			  =		outputs.logits
        __UpperCamelCase     :Any			  =		torch.argmax(logits[:, 2]).item()
        return self._labels[label_id]





