


"""simple docstring"""



from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
		from PIL import Image

		from ..image_utils import load_image

if is_tf_available():
		import tensorflow as tf

		from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
		from ..tf_utils import stable_softmax

if is_torch_available():
		from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

lowercase_							=							logging.get_logger(__name__)







@add_end_docstrings(__snake_case							)
class    __a						( __snake_case							):







				def __init__( self      ,	*UpperCAmelCase      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					super().__init__(*UpperCAmelCase      ,	**UpperCAmelCase   )
					requires_backends(self      ,	'''vision'''   )
					self.check_model_type(
					    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
					    if self.framework == '''tf'''
					    else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase=None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			{}
					if top_k is not None:
						lowerCAmelCase_      							=			top_k
					return {}, {}, postprocess_params







				def __call__( self      ,	UpperCAmelCase      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					return super().__call__(UpperCAmelCase      ,	**UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			load_image(UpperCAmelCase   )
					lowerCAmelCase_      							=			self.image_processor(images=UpperCAmelCase      ,	return_tensors=self.framework   )
					return model_inputs







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model(**UpperCAmelCase   )
					return model_outputs







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase=5   ):

					'''simple docstring'''






					if top_k > self.model.config.num_labels:
						lowerCAmelCase_      							=			self.model.config.num_labels

					if self.framework == "pt":
						lowerCAmelCase_      							=			model_outputs.logits.softmax(-1   )[0]
						lowerCAmelCase_							,	lowerCAmelCase_      							=			probs.topk(UpperCAmelCase   )
					elif self.framework == "tf":
						lowerCAmelCase_      							=			stable_softmax(model_outputs.logits      ,	axis=-1   )[0]
						lowerCAmelCase_      							=			tf.math.top_k(UpperCAmelCase      ,	k=UpperCAmelCase   )
						lowerCAmelCase_							,	lowerCAmelCase_      							=			topk.values.numpy(), topk.indices.numpy()
					else:
						raise ValueError(F"""Unsupported framework: {self.framework}"""   )

					lowerCAmelCase_      							=			scores.tolist()
					lowerCAmelCase_      							=			ids.tolist()
					return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(UpperCAmelCase      ,	UpperCAmelCase   )]



"""simple docstring"""



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{'vocab_file': 'vocab.txt'}

lowercase_							=							{
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

lowercase_							=							{
    'YituTech/conv-bert-base': 5_12,
    'YituTech/conv-bert-medium-small': 5_12,
    'YituTech/conv-bert-small': 5_12,
}


lowercase_							=							{
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Optional[int]			       =VOCAB_FILES_NAMES
				lowerCamelCase     :       List[str]			       =PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase     :       str			       =PRETRAINED_INIT_CONFIGURATION
				lowerCamelCase     :       Any			       =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase     :       List[str]			       =ConvBertTokenizer







				def __init__( self      ,	UpperCAmelCase=None      ,	UpperCAmelCase=None      ,	UpperCAmelCase=True      ,	UpperCAmelCase="[UNK]"      ,	UpperCAmelCase="[SEP]"      ,	UpperCAmelCase="[PAD]"      ,	UpperCAmelCase="[CLS]"      ,	UpperCAmelCase="[MASK]"      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					super().__init__(
					    UpperCAmelCase      ,	tokenizer_file=UpperCAmelCase      ,	do_lower_case=UpperCAmelCase      ,	unk_token=UpperCAmelCase      ,	sep_token=UpperCAmelCase      ,	pad_token=UpperCAmelCase      ,	cls_token=UpperCAmelCase      ,	mask_token=UpperCAmelCase      ,	tokenize_chinese_chars=UpperCAmelCase      ,	strip_accents=UpperCAmelCase      ,	**UpperCAmelCase      ,	)

					lowerCAmelCase_      							=			json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
					if (
					    normalizer_state.get('''lowercase'''      ,	UpperCAmelCase   ) != do_lower_case
					    or normalizer_state.get('''strip_accents'''      ,	UpperCAmelCase   ) != strip_accents
					    or normalizer_state.get('''handle_chinese_chars'''      ,	UpperCAmelCase   ) != tokenize_chinese_chars
					):
						lowerCAmelCase_      							=			getattr(UpperCAmelCase      ,	normalizer_state.pop('''type'''   )   )
						lowerCAmelCase_      							=			do_lower_case
						lowerCAmelCase_      							=			strip_accents
						lowerCAmelCase_      							=			tokenize_chinese_chars
						lowerCAmelCase_      							=			normalizer_class(**UpperCAmelCase   )

					lowerCAmelCase_      							=			do_lower_case







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase=None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[self.cls_token_id] + token_ids_a + [self.sep_token_id]

					if token_ids_a:
						output += token_ids_a + [self.sep_token_id]

					return output







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[self.sep_token_id]
					lowerCAmelCase_      							=			[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   ) * [0] + len(token_ids_a + sep   ) * [1]







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self._tokenizer.model.save(UpperCAmelCase      ,	name=UpperCAmelCase   )
					return tuple(UpperCAmelCase   )