"""simple docstring"""





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_     =	{
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"xlm"
				a			=						{
				    "hidden_size": "emb_dim",
				    "num_attention_heads": "n_heads",
				    "num_hidden_layers": "n_layers",
				    "n_words": "vocab_size",  # For backward compatibility
				}





				def __init__(      self							:							Optional[Any]      ,    _A							:							Tuple=3_0_1_4_5      ,    _A							:							int=2_0_4_8      ,    _A							:							int=1_2      ,    _A							:							Any=1_6      ,    _A							:							Dict=0.1      ,    _A							:							List[str]=0.1      ,    _A							:							Any=True      ,    _A							:							Dict=False      ,    _A							:							Dict=False      ,    _A							:							List[Any]=False      ,    _A							:							Tuple=1      ,    _A							:							List[Any]=True      ,    _A							:							int=5_1_2      ,    _A							:							Optional[int]=2_0_4_8**-0.5      ,    _A							:							Union[str, Any]=1e-12      ,    _A							:							Tuple=0.02      ,    _A							:							Optional[Any]=0      ,    _A							:							int=1      ,    _A							:							Dict=2      ,    _A							:							Union[str, Any]=3      ,    _A							:							int=5      ,    _A							:							List[str]=True      ,    _A							:							str="first"      ,    _A							:							int=True      ,    _A							:							str=None      ,    _A							:							Optional[int]=True      ,    _A							:							Any=0.1      ,    _A							:							List[Any]=5      ,    _A							:							int=5      ,    _A							:							Any=0      ,    _A							:							Dict=0      ,    _A							:							Union[str, Any]=2      ,    _A							:							Tuple=0      ,    **_A							:							Union[str, Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    vocab_size
											_SCREAMING_SNAKE_CASE		:						Any			  =    emb_dim
											_SCREAMING_SNAKE_CASE		:						int			  =    n_layers
											_SCREAMING_SNAKE_CASE		:						str			  =    n_heads
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    dropout
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    attention_dropout
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    gelu_activation
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    sinusoidal_embeddings
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    causal
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    asm
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    n_langs
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    use_lang_emb
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    layer_norm_eps
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    bos_index
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    eos_index
											_SCREAMING_SNAKE_CASE		:						Any			  =    pad_index
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    unk_index
											_SCREAMING_SNAKE_CASE		:						str			  =    mask_index
											_SCREAMING_SNAKE_CASE		:						str			  =    is_encoder
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    max_position_embeddings
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    embed_init_std
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    init_std
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    summary_type
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    summary_use_proj
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    summary_activation
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    summary_proj_to_labels
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    summary_first_dropout
											_SCREAMING_SNAKE_CASE		:						Any			  =    start_n_top
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    end_n_top
											_SCREAMING_SNAKE_CASE		:						int			  =    mask_token_id
											_SCREAMING_SNAKE_CASE		:						str			  =    lang_id

											if "n_words" in kwargs:
																		_SCREAMING_SNAKE_CASE		:						int			  =    kwargs["""n_words"""]

											super().__init__(pad_token_id=_A      ,    bos_token_id=_A      ,    **_A)




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				@property
				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											if self.task == "multiple-choice":
																		_SCREAMING_SNAKE_CASE		:						int			  =    {0: """batch""", 1: """choice""", 2: """sequence"""}
											else:
																		_SCREAMING_SNAKE_CASE		:						Dict			  =    {0: """batch""", 1: """sequence"""}
											return OrderedDict(
											    [
											        ("""input_ids""", dynamic_axis),
											        ("""attention_mask""", dynamic_axis),
											        ("""token_type_ids""", dynamic_axis),
											    ])



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







				"""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 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







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



											"""simple docstring"""







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





				def 		_lowerCAmelCase		(      self							:							Tuple      ,    _A							:							Optional[Any]):



											"""simple docstring"""







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


