


'''simple docstring'''

import numpy as np

from transformers import Pipeline





def __snake_case					(      UpperCAmelCase_						:						Dict		):
 lowerCamelCase_      =  np.max(UpperCAmelCase_					,				axis=-1					,				keepdims=UpperCAmelCase_		)
 lowerCamelCase_      =  np.exp(outputs - maxes		)
 return shifted_exp / shifted_exp.sum(axis=-1					,				keepdims=UpperCAmelCase_		)







class      snake_case    (    lowercase			):





  """simple docstring"""




  def   snake_case		(    self			,  **UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  {}
   if "second_text" in kwargs:
    lowerCamelCase_      =  kwargs["second_text"]
   return preprocess_kwargs, {}, {}






  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase=None     ):







   """simple docstring"""
   return self.tokenizer(UpperCamelCase			,  text_pair=UpperCamelCase			,  return_tensors=self.framework     )






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   return self.model(**UpperCamelCase     )







  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  model_outputs.logits[0].numpy()
   lowerCamelCase_      =  softmax(UpperCamelCase     )

   lowerCamelCase_      =  np.argmax(UpperCamelCase     )
   lowerCamelCase_      =  self.model.config.idalabel[best_class]
   lowerCamelCase_      =  probabilities[best_class].item()
   lowerCamelCase_      =  logits.tolist()
   return {"label": label, "score": score, "logits": logits}










import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin







class     __snake_case       (							unittest.TestCase   ,			__lowerCamelCase			):





       '''simple docstring'''







       def 							UpperCAmelCase__ (  self :    Union[str, Any]		):
         __snake_case:						Optional[int]   =						load_tool("""text-classification"""		)
         self.tool.setup()
         __snake_case:						Dict   =						load_tool("""text-classification"""							,				remote=A		)




       def 							UpperCAmelCase__ (  self :    Optional[int]		):
         __snake_case:						List[str]   =						self.tool("""That's quite cool"""							,				["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)




       def 							UpperCAmelCase__ (  self :    Dict		):
         __snake_case:						List[str]   =						self.remote_tool("""That's quite cool"""							,				["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)




       def 							UpperCAmelCase__ (  self :    Optional[Any]		):
         __snake_case:						Optional[Any]   =						self.tool(text="""That's quite cool"""							,				labels=["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)






       def 							UpperCAmelCase__ (  self :    Tuple		):
         __snake_case:						int   =						self.remote_tool(text="""That's quite cool"""							,				labels=["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)






