"""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_    (			lowerCAmelCase					):



				"""simple docstring"""
				_lowerCAmelCase     :    Optional[int]			  =						"""facebook/bart-large-mnli"""
				_lowerCAmelCase     :    Optional[Any]			  =						(
				    """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     :    Union[str, Any]			  =						"""text_classifier"""
				_lowerCAmelCase     :    int			  =						AutoTokenizer
				_lowerCAmelCase     :    Optional[int]			  =						AutoModelForSequenceClassification

				_lowerCAmelCase     :    str			  =						["""text""", ["""text"""]]
				_lowerCAmelCase     :    str			  =						["""text"""]

				def 		snake_case (				self    ):






										"""simple docstring"""

										super().setup()
										snake_case								=			self.model.config
										snake_case								=			-1
										for idx, label in config.idalabel.items():
																if label.lower().startswith('entail'    ):
																						snake_case								=			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 		snake_case (				self		,    lowerCAmelCase		,    lowerCAmelCase    ):






										"""simple docstring"""

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

				def 		snake_case (				self		,    lowerCAmelCase    ):






										"""simple docstring"""

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



"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__      						=  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__      						=  {
    "weiweishi/roc-bert-base-zh": "https://huggingface.co/weiweishi/roc-bert-base-zh/resolve/main/config.json",
}



class   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""
				_lowerCAmelCase     :    Dict			  =						"""roc_bert"""

				def __init__(				self		,    lowerCAmelCase=3_05_22		,    lowerCAmelCase=7_68		,    lowerCAmelCase=12		,    lowerCAmelCase=12		,    lowerCAmelCase=30_72		,    lowerCAmelCase="gelu"		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.1		,    lowerCAmelCase=5_12		,    lowerCAmelCase=2		,    lowerCAmelCase=0.02		,    lowerCAmelCase=1E-12		,    lowerCAmelCase=True		,    lowerCAmelCase=0		,    lowerCAmelCase="absolute"		,    lowerCAmelCase=None		,    lowerCAmelCase=True		,    lowerCAmelCase=True		,    lowerCAmelCase=7_68		,    lowerCAmelCase=9_10		,    lowerCAmelCase=5_12		,    lowerCAmelCase=2_48_58		,    lowerCAmelCase=True		,    **lowerCAmelCase		,    ):






										"""simple docstring"""

										snake_case								=			vocab_size
										snake_case								=			max_position_embeddings
										snake_case								=			hidden_size
										snake_case								=			num_hidden_layers
										snake_case								=			num_attention_heads
										snake_case								=			intermediate_size
										snake_case								=			hidden_act
										snake_case								=			hidden_dropout_prob
										snake_case								=			attention_probs_dropout_prob
										snake_case								=			initializer_range
										snake_case								=			type_vocab_size
										snake_case								=			layer_norm_eps
										snake_case								=			use_cache
										snake_case								=			enable_pronunciation
										snake_case								=			enable_shape
										snake_case								=			pronunciation_embed_dim
										snake_case								=			pronunciation_vocab_size
										snake_case								=			shape_embed_dim
										snake_case								=			shape_vocab_size
										snake_case								=			concat_input
										snake_case								=			position_embedding_type
										snake_case								=			classifier_dropout
										super().__init__(pad_token_id=lowerCAmelCase		,    **lowerCAmelCase    )


