"""simple docstring"""





import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mvp import MvpTokenizer


lowerCAmelCase_     =	logging.get_logger(__name__)


lowerCAmelCase_     =	{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

# See all MVP models at https://huggingface.co/models?filter=mvp
lowerCAmelCase_     =	{
    '''vocab_file''': {
        '''RUCAIBox/mvp''': '''https://huggingface.co/RUCAIBox/mvp/resolve/main/vocab.json''',
    },
    '''added_tokens.json''': {
        '''RUCAIBox/mvp''': '''https://huggingface.co/RUCAIBox/mvp/resolve/main/added_tokens.json''',
    },
    '''merges_file''': {
        '''RUCAIBox/mvp''': '''https://huggingface.co/RUCAIBox/mvp/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''RUCAIBox/mvp''': '''https://huggingface.co/RUCAIBox/mvp/resolve/main/tokenizer.json''',
    },
}

lowerCAmelCase_     =	{
    '''RUCAIBox/mvp''': 1024,
}




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						VOCAB_FILES_NAMES
				a			=						PRETRAINED_VOCAB_FILES_MAP
				a			=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				a			=						["input_ids", "attention_mask"]
				a			=						MvpTokenizer





				def __init__(      self							:							Optional[Any]      ,    _A							:							List[str]=None      ,    _A							:							Optional[int]=None      ,    _A							:							Optional[Any]=None      ,    _A							:							Optional[int]="replace"      ,    _A							:							Optional[Any]="<s>"      ,    _A							:							Optional[Any]="</s>"      ,    _A							:							str="</s>"      ,    _A							:							Union[str, Any]="<s>"      ,    _A							:							Union[str, Any]="<unk>"      ,    _A							:							Any="<pad>"      ,    _A							:							Optional[Any]="<mask>"      ,    _A							:							int=False      ,    _A							:							Optional[int]=True      ,    **_A							:							Optional[Any]      ,    ):



											"""simple docstring"""







											super().__init__(
											    _A      ,    _A      ,    tokenizer_file=_A      ,    errors=_A      ,    bos_token=_A      ,    eos_token=_A      ,    sep_token=_A      ,    cls_token=_A      ,    unk_token=_A      ,    pad_token=_A      ,    mask_token=_A      ,    add_prefix_space=_A      ,    trim_offsets=_A      ,    **_A      ,    )

											_SCREAMING_SNAKE_CASE		:						str			  =    json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__())
											if pre_tok_state.get("""add_prefix_space"""      ,    _A) != add_prefix_space:
																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    getattr(_A      ,    pre_tok_state.pop("""type"""))
																		_SCREAMING_SNAKE_CASE		:						str			  =    add_prefix_space
																		_SCREAMING_SNAKE_CASE		:						int			  =    pre_tok_class(**_A)

											_SCREAMING_SNAKE_CASE		:						str			  =    add_prefix_space

											# the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    """post_processor"""
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    getattr(self.backend_tokenizer      ,    _A      ,    _A)
											if tokenizer_component_instance:
																		_SCREAMING_SNAKE_CASE		:						Dict			  =    json.loads(tokenizer_component_instance.__getstate__())

																		# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
																		if "sep" in state:
																									_SCREAMING_SNAKE_CASE		:						Any			  =    tuple(state["""sep"""])
																		if "cls" in state:
																									_SCREAMING_SNAKE_CASE		:						str			  =    tuple(state["""cls"""])

																		_SCREAMING_SNAKE_CASE		:						Any			  =    False

																		if state.get("""add_prefix_space"""      ,    _A) != add_prefix_space:
																									_SCREAMING_SNAKE_CASE		:						str			  =    add_prefix_space
																									_SCREAMING_SNAKE_CASE		:						Dict			  =    True

																		if state.get("""trim_offsets"""      ,    _A) != trim_offsets:
																									_SCREAMING_SNAKE_CASE		:						List[Any]			  =    trim_offsets
																									_SCREAMING_SNAKE_CASE		:						Tuple			  =    True

																		if changes_to_apply:
																									_SCREAMING_SNAKE_CASE		:						str			  =    getattr(_A      ,    state.pop("""type"""))
																									_SCREAMING_SNAKE_CASE		:						int			  =    component_class(**_A)
																									setattr(self.backend_tokenizer      ,    _A      ,    _A)





				@property
				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											if self._mask_token is None:
																		if self.verbose:
																									logger.error("""Using mask_token, but it is not set yet.""")
																		return None
											return str(self._mask_token)





				@mask_token.setter
				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    AddedToken(_A      ,    lstrip=_A      ,    rstrip=_A) if isinstance(_A      ,    _A) else value
											_SCREAMING_SNAKE_CASE		:						Any			  =    value





				def 		_lowerCAmelCase		(      self							:							List[str]      ,    *_A							:							Dict      ,    **_A							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    kwargs.get("""is_split_into_words"""      ,    _A)

											if is_split_into_words and not self.add_prefix_space:
																		raise ValueError(
																		    f"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
																		    """to use it with pretokenized inputs.""")

											return super()._batch_encode_plus(*_A      ,    **_A)





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



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    kwargs.get("""is_split_into_words"""      ,    _A)

											if is_split_into_words and not self.add_prefix_space:
																		raise ValueError(
																		    f"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
																		    """to use it with pretokenized inputs.""")

											return super()._encode_plus(*_A      ,    **_A)





				def 		_lowerCAmelCase		(      self							:							Optional[Any]      ,    _A							:							str      ,    _A							:							Optional[str] = None):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Dict			  =    self._tokenizer.model.save(_A      ,    name=_A)
											return tuple(_A)





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							List[str]      ,    _A							:							List[str]=None):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Any			  =    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
											if token_ids_a is None:
																		return output

											return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							List[int]      ,    _A							:							Optional[List[int]] = None):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    [self.sep_token_id]
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    [self.cls_token_id]

											if token_ids_a is None:
																		return len(cls + token_ids_a + sep) * [0]
											return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]



"""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]


