
'''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     __snake_case		(   a__):
					_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      ):

									"""simple docstring"""


									super().setup()
									lowerCamelCase					:			Optional[Any]									= self.model.config
									lowerCamelCase					:			Optional[int]									= -1
									for idx, label in config.idalabel.items():
													if label.lower().startswith('entail'      ):
																	lowerCamelCase					:			List[Any]									= int(A      )
									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,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			str									= labels
									return self.pre_processor(
									    [text] * len(A      ),    [F'''This example is {label}''' for label in labels],    return_tensors='pt',    padding='max_length',    )




					def     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


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


'''simple docstring'''






import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

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


A			      =      logging.get_logger(__name__)

A			      =      {
    'nvidia/segformer-b0-finetuned-ade-512-512': (
        'https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class     __snake_case		(   a__):
					_lowerCAmelCase			     =	'''segformer'''
					def __init__(     self,    A=3,    A=4,    A=[2, 2, 2, 2],    A=[8, 4, 2, 1],    A=[32, 64, 160, 256],    A=[7, 3, 3, 3],    A=[4, 2, 2, 2],    A=[1, 2, 5, 8],    A=[4, 4, 4, 4],    A="gelu",    A=0.0,    A=0.0,    A=0.1,    A=0.02,    A=0.1,    A=1e-6,    A=256,    A=255,    **A,    ):

									"""simple docstring"""


									super().__init__(**A      )

									if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
													warnings.warn(
													    'Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'
													    ' removed, as the behaviour will default to that of reshape_last_stage = True.',    A,    )

									lowerCamelCase					:			Tuple									= num_channels
									lowerCamelCase					:			Dict									= num_encoder_blocks
									lowerCamelCase					:			Dict									= depths
									lowerCamelCase					:			Any									= sr_ratios
									lowerCamelCase					:			List[Any]									= hidden_sizes
									lowerCamelCase					:			List[Any]									= patch_sizes
									lowerCamelCase					:			Tuple									= strides
									lowerCamelCase					:			int									= mlp_ratios
									lowerCamelCase					:			Dict									= num_attention_heads
									lowerCamelCase					:			Union[str, Any]									= hidden_act
									lowerCamelCase					:			Tuple									= hidden_dropout_prob
									lowerCamelCase					:			Optional[int]									= attention_probs_dropout_prob
									lowerCamelCase					:			List[str]									= classifier_dropout_prob
									lowerCamelCase					:			Union[str, Any]									= initializer_range
									lowerCamelCase					:			Union[str, Any]									= drop_path_rate
									lowerCamelCase					:			int									= layer_norm_eps
									lowerCamelCase					:			Any									= decoder_hidden_size
									lowerCamelCase					:			Optional[int]									= kwargs.get('reshape_last_stage',    A      )
									lowerCamelCase					:			Any									= semantic_loss_ignore_index





class     __snake_case		(   a__):
					_lowerCAmelCase			     =	version.parse('''1.11''')
					@property
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return OrderedDict(
									    [
									        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
									    ]      )
					@property
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return 1e-4




					@property
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return 12
