

from collections import OrderedDict
from typing import Mapping

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


lowerCAmelCase__								=		logging.get_logger(__name__)

lowerCAmelCase__								=		{
    """distilbert-base-uncased""": """https://huggingface.co/distilbert-base-uncased/resolve/main/config.json""",
    """distilbert-base-uncased-distilled-squad""": (
        """https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json"""
    ),
    """distilbert-base-cased""": """https://huggingface.co/distilbert-base-cased/resolve/main/config.json""",
    """distilbert-base-cased-distilled-squad""": (
        """https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json"""
    ),
    """distilbert-base-german-cased""": """https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json""",
    """distilbert-base-multilingual-cased""": (
        """https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json"""
    ),
    """distilbert-base-uncased-finetuned-sst-2-english""": (
        """https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json"""
    ),
}







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		a__					       =  "distilbert"
		a__					       =  {
		    "hidden_size": "dim",
		    "num_attention_heads": "n_heads",
		    "num_hidden_layers": "n_layers",
		}


		def __init__(				self	,       __snake_case=3_05_22	,       __snake_case=5_12	,       __snake_case=False	,       __snake_case=6	,       __snake_case=12	,       __snake_case=7_68	,       __snake_case=4 * 7_68	,       __snake_case=0.1	,       __snake_case=0.1	,       __snake_case="gelu"	,       __snake_case=0.0_2	,       __snake_case=0.1	,       __snake_case=0.2	,       __snake_case=0	,       **__snake_case	,       ):
			_UpperCamelCase   :		Optional[Any]			=						vocab_size
			_UpperCamelCase   :		Union[str, Any]			=						max_position_embeddings
			_UpperCamelCase   :		Dict			=						sinusoidal_pos_embds
			_UpperCamelCase   :		Optional[int]			=						n_layers
			_UpperCamelCase   :		Union[str, Any]			=						n_heads
			_UpperCamelCase   :		Union[str, Any]			=						dim
			_UpperCamelCase   :		Union[str, Any]			=						hidden_dim
			_UpperCamelCase   :		Tuple			=						dropout
			_UpperCamelCase   :		Union[str, Any]			=						attention_dropout
			_UpperCamelCase   :		Optional[int]			=						activation
			_UpperCamelCase   :		Union[str, Any]			=						initializer_range
			_UpperCamelCase   :		Union[str, Any]			=						qa_dropout
			_UpperCamelCase   :		Union[str, Any]			=						seq_classif_dropout
			super().__init__(**__snake_case	,       pad_token_id=__snake_case)







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




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







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


		"""simple docstring"""




		a__					       =  "facebook/bart-large-mnli"
		a__					       =  (
		    "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__					       =  "text_classifier"
		a__					       =  AutoTokenizer
		a__					       =  AutoModelForSequenceClassification

		a__					       =  ["text", ["text"]]
		a__					       =  ["text"]


		def 		A__					(				self):
			super().setup()
			_UpperCamelCase   :		List[Any]			=						self.model.config
			_UpperCamelCase   :		Optional[int]			=						-1
			for idx, label in config.idalabel.items():
				if label.lower().startswith('entail'):
					_UpperCamelCase   :		Tuple			=						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	,       __snake_case	,       __snake_case):
			_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	,       __snake_case):
			_UpperCamelCase   :		str			=						outputs.logits
			_UpperCamelCase   :		Optional[Any]			=						torch.argmax(logits[:, 2]).item()
			return self._labels[label_id]




