






'''simple docstring'''




import torch

from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer
from .base import PipelineTool

class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''facebook/bart-large-mnli'''
	_lowerCamelCase              =  (
	    '''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.'''
	)
	_lowerCamelCase              =  '''text_classifier'''
	_lowerCamelCase              =  AutoTokenizer
	_lowerCamelCase              =  AutoModelForSequenceClassification

	_lowerCamelCase              =  ['''text''', ['''text''']]
	_lowerCamelCase              =  ['''text''']

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





	def      __UpperCamelCase							(      self   :						Union[str, Any]  ,					UpperCAmelCase_   :						Tuple):
			UpperCamelCase__				:					Tuple					=					outputs.logits
			UpperCamelCase__				:					Union[str, Any]					=					torch.argmax(logits[:, 2]).item()
			return self._labels[label_id]












'''simple docstring'''




def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     list[str]:
		return [sentence[i : i + ngram_size] for i in range(len(lowerCamelCase_) - ngram_size + 1)]


if __name__ == "__main__":
		from doctest import testmod

		testmod()




