

# 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 				a  (	lowerCamelCase__				):
						_lowercase    						=			"facebook/bart-large-mnli"
						_lowercase    						=			(
						    "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."
						)
						_lowercase    						=			"text_classifier"
						_lowercase    						=			AutoTokenizer
						_lowercase    						=			AutoModelForSequenceClassification

						_lowercase    						=			["text", ["text"]]
						_lowercase    						=			["text"]


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


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


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





						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		int 		=    outputs.logits
										_UpperCAmelCase       :		Union[str, Any] 		=    torch.argmax(logits[:, 2]	).item()
										return self._labels[label_id]





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


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_        =      {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/config.json'}

class 				a  (	UpperCAmelCase				):
						_lowercase    						=			"openai-gpt"
						_lowercase    						=			{
						    "max_position_embeddings": "n_positions",
						    "hidden_size": "n_embd",
						    "num_attention_heads": "n_head",
						    "num_hidden_layers": "n_layer",
						}


						def __init__(       self						,					A_=40478						,					A_=512						,					A_=768						,					A_=12						,					A_=12						,					A_="gelu"						,					A_=0.1						,					A_=0.1						,					A_=0.1						,					A_=1e-5						,					A_=0.02						,					A_="cls_index"						,					A_=True						,					A_=None						,					A_=True						,					A_=0.1						,					**A_						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    vocab_size
										_UpperCAmelCase       :		str 		=    n_positions
										_UpperCAmelCase       :		List[Any] 		=    n_embd
										_UpperCAmelCase       :		Dict 		=    n_layer
										_UpperCAmelCase       :		Any 		=    n_head
										_UpperCAmelCase       :		int 		=    afn
										_UpperCAmelCase       :		int 		=    resid_pdrop
										_UpperCAmelCase       :		Tuple 		=    embd_pdrop
										_UpperCAmelCase       :		Optional[Any] 		=    attn_pdrop
										_UpperCAmelCase       :		Any 		=    layer_norm_epsilon
										_UpperCAmelCase       :		List[str] 		=    initializer_range
										_UpperCAmelCase       :		Union[str, Any] 		=    summary_type
										_UpperCAmelCase       :		List[Any] 		=    summary_use_proj
										_UpperCAmelCase       :		Optional[Any] 		=    summary_activation
										_UpperCAmelCase       :		int 		=    summary_first_dropout
										_UpperCAmelCase       :		List[str] 		=    summary_proj_to_labels
										super().__init__(**A_	)


