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


SCREAMING_SNAKE_CASE							:Tuple										=    logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:Tuple										=    {
    'facebook/xglm-564M': 'https://huggingface.co/facebook/xglm-564M/resolve/main/config.json',
    # See all XGLM models at https://huggingface.co/models?filter=xglm
}





class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					"xglm"
	snake_case_    =					["past_key_values"]

	snake_case_    =					{
	    "num_attention_heads": "attention_heads",
	    "hidden_size": "d_model",
	    "num_hidden_layers": "num_layers",
	}






	def __init__(	self :			Tuple							,A :			Union[str, Any]=25_60_08							,A :			Optional[Any]=20_48							,A :			int=10_24							,A :			Tuple=40_96							,A :			Optional[int]=24							,A :			Dict=16							,A :			Union[str, Any]="gelu"							,A :			Tuple=0.1							,A :			Dict=0.1							,A :			Optional[Any]=0.0							,A :			str=0.0							,A :			int=0.02							,A :			List[Any]=True							,A :			Dict=True							,A :			Tuple=2							,A :			Dict=1							,A :			Dict=0							,A :			List[str]=2							,**A :			Any							,):
					__A             =			vocab_size
					__A             =			max_position_embeddings
					__A             =			d_model
					__A             =			ffn_dim
					__A             =			num_layers
					__A             =			attention_heads
					__A             =			activation_function
					__A             =			dropout
					__A             =			attention_dropout
					__A             =			activation_dropout
					__A             =			layerdrop
					__A             =			init_std
					__A             =			scale_embedding  # scale factor will be sqrt(d_model) if True
					__A             =			use_cache

					super().__init__(
					    pad_token_id=A							,bos_token_id=A							,eos_token_id=A							,decoder_start_token_id=A							,**A							,)


# 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 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					"facebook/bart-large-mnli"
	snake_case_    =					(
	    "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."
	)
	snake_case_    =					"text_classifier"
	snake_case_    =					AutoTokenizer
	snake_case_    =					AutoModelForSequenceClassification

	snake_case_    =					["text", ["text"]]
	snake_case_    =					["text"]






	def     UpperCamelCase_  (	self :			str			):
					super().setup()
					__A             =			self.model.config
					__A             =			-1
					for idx, label in config.idalabel.items():
									if label.lower().startswith("entail"			):
													__A             =			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     UpperCamelCase_  (	self :			int							,A :			Optional[Any]							,A :			Dict			):
					__A             =			labels
					return self.pre_processor(
					    [text] * len(A			)							,[f'''This example is {label}''' for label in labels]							,return_tensors="pt"							,padding="max_length"							,)







	def     UpperCamelCase_  (	self :			Union[str, Any]							,A :			Tuple			):
					__A             =			outputs.logits
					__A             =			torch.argmax(logits[:, 2]			).item()
					return self._labels[label_id]
