






"""simple docstring"""
import functools
import operator

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


_lowerCAmelCase     =							logging.get_logger(__name__)

_lowerCAmelCase     =							{
    "asapp/sew-tiny-100k": "https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json",
    # See all SEW models at https://huggingface.co/models?filter=sew
}



class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				Any    =				"""sew"""





	def __init__(self     ,     lowerCAmelCase_=32     ,     lowerCAmelCase_=768     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=3072     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_="gelu"     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.0     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=1e-5     ,     lowerCAmelCase_="group"     ,     lowerCAmelCase_="gelu"     ,     lowerCAmelCase_=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)     ,     lowerCAmelCase_=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)     ,     lowerCAmelCase_=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)     ,     lowerCAmelCase_=False     ,     lowerCAmelCase_=128     ,     lowerCAmelCase_=16     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=0.05     ,     lowerCAmelCase_=10     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=0.0     ,     lowerCAmelCase_=10     ,     lowerCAmelCase_=0     ,     lowerCAmelCase_="mean"     ,     lowerCAmelCase_=False     ,     lowerCAmelCase_=False     ,     lowerCAmelCase_=256     ,     lowerCAmelCase_=0     ,     lowerCAmelCase_=1     ,     lowerCAmelCase_=2     ,     **lowerCAmelCase_     ,     ):
		super().__init__(**lowerCAmelCase_     ,     pad_token_id=lowerCAmelCase_     ,     bos_token_id=lowerCAmelCase_     ,     eos_token_id=lowerCAmelCase_							)
		A_		:						int	    =   hidden_size
		A_		:						List[str]	    =   feat_extract_norm
		A_		:						Union[str, Any]	    =   feat_extract_activation
		A_		:						int	    =   list(lowerCAmelCase_							)
		A_		:						Tuple	    =   list(lowerCAmelCase_							)
		A_		:						int	    =   list(lowerCAmelCase_							)
		A_		:						Tuple	    =   conv_bias
		A_		:						Union[str, Any]	    =   num_conv_pos_embeddings
		A_		:						Optional[int]	    =   num_conv_pos_embedding_groups
		A_		:						Any	    =   len(self.conv_dim							)
		A_		:						Optional[Any]	    =   num_hidden_layers
		A_		:						int	    =   intermediate_size
		A_		:						Dict	    =   squeeze_factor
		A_		:						Tuple	    =   hidden_act
		A_		:						Any	    =   num_attention_heads
		A_		:						List[Any]	    =   hidden_dropout
		A_		:						Union[str, Any]	    =   attention_dropout
		A_		:						List[Any]	    =   activation_dropout
		A_		:						Optional[Any]	    =   feat_proj_dropout
		A_		:						Any	    =   final_dropout
		A_		:						Tuple	    =   layerdrop
		A_		:						Optional[Any]	    =   layer_norm_eps
		A_		:						Dict	    =   initializer_range
		A_		:						str	    =   vocab_size

		if (
		    (len(self.conv_stride							) != self.num_feat_extract_layers)
		    or (len(self.conv_kernel							) != self.num_feat_extract_layers)
		    or (len(self.conv_dim							) != self.num_feat_extract_layers)
		):
			raise ValueError(
			    """Configuration for convolutional layers is incorrect."""
			    """It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"""
			    f"""but is `len(config.conv_dim) = {len(self.conv_dim							)}`, `len(config.conv_stride)"""
			    f"""= {len(self.conv_stride							)}`, `len(config.conv_kernel) = {len(self.conv_kernel							)}`."""							)

		# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
		A_		:						str	    =   apply_spec_augment
		A_		:						List[str]	    =   mask_time_prob
		A_		:						Union[str, Any]	    =   mask_time_length
		A_		:						Any	    =   mask_time_min_masks
		A_		:						List[Any]	    =   mask_feature_prob
		A_		:						List[Any]	    =   mask_feature_length
		A_		:						Union[str, Any]	    =   mask_feature_min_masks

		# ctc loss
		A_		:						Any	    =   ctc_loss_reduction
		A_		:						Optional[Any]	    =   ctc_zero_infinity

		# sequence classification
		A_		:						Any	    =   use_weighted_layer_sum
		A_		:						List[str]	    =   classifier_proj_size





	@property
	def    lowerCamelCase(self							):
		return functools.reduce(operator.mul     ,     self.conv_stride     ,     1							)









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





	"""simple docstring"""




	_A       :				Optional[int]    =				"""facebook/bart-large-mnli"""
	_A       :				str    =				(
	    """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       :				List[str]    =				"""text_classifier"""
	_A       :				Optional[int]    =				AutoTokenizer
	_A       :				Optional[Any]    =				AutoModelForSequenceClassification

	_A       :				List[str]    =				["""text""", ["""text"""]]
	_A       :				Dict    =				["""text"""]





	def    lowerCamelCase(self							):
		super().setup()
		A_		:						int	    =   self.model.config
		A_		:						List[str]	    =   -1
		for idx, label in config.idalabel.items():
			if label.lower().startswith("""entail"""							):
				A_		:						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    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						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    lowerCamelCase(self     ,     lowerCAmelCase_							):
		A_		:						str	    =   outputs.logits
		A_		:						Optional[int]	    =   torch.argmax(logits[:, 2]							).item()
		return self._labels[label_id]

