



'''simple docstring'''





import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TextClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
_lowerCAmelCase										=     {'''LayoutLMv2Config''', '''LayoutLMv3Config'''}






@is_pipeline_test
class 	lowerCAmelCase_(    unittest.TestCase					):
		'''simple docstring'''




		__lowercase							:				str           =				MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
		__lowercase							:				Optional[int]           =				TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

		if model_mapping is not None:
				__lowercase							:				Optional[Any]           =				{config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
		if tf_model_mapping is not None:
				__lowercase							:				List[Any]           =				{
				    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
				}




		@require_torch
		def 							UpperCAmelCase_     (   self				)   ->		List[Any]:
						lowerCAmelCase__			:  Any											= pipeline(
						    task="""text-classification"""  ,model="""hf-internal-testing/tiny-random-distilbert"""  ,framework="""pt"""				)

						lowerCAmelCase__			:  str											= text_classifier("""This is great !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}]				)

						lowerCAmelCase__			:  List[str]											= text_classifier("""This is great !"""  ,top_k=2				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}]				)

						lowerCAmelCase__			:  Tuple											= text_classifier(["""This is great !""", """This is bad"""]  ,top_k=2				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[
						        [{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}],
						        [{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}],
						    ]  ,)

						lowerCAmelCase__			:  Optional[int]											= text_classifier("""This is great !"""  ,top_k=1				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}]				)

						# Legacy behavior
						lowerCAmelCase__			:  Optional[Any]											= text_classifier("""This is great !"""  ,return_all_scores=__UpperCAmelCase				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}]				)

						lowerCAmelCase__			:  Union[str, Any]											= text_classifier("""This is great !"""  ,return_all_scores=__UpperCAmelCase				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[[{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}]]				)

						lowerCAmelCase__			:  int											= text_classifier(["""This is great !""", """Something else"""]  ,return_all_scores=__UpperCAmelCase				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[
						        [{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}],
						        [{"""label""": """LABEL_0""", """score""": 0.5_0_4}, {"""label""": """LABEL_1""", """score""": 0.4_9_6}],
						    ]  ,)

						lowerCAmelCase__			:  Dict											= text_classifier(["""This is great !""", """Something else"""]  ,return_all_scores=__UpperCAmelCase				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[
						        {"""label""": """LABEL_0""", """score""": 0.5_0_4},
						        {"""label""": """LABEL_0""", """score""": 0.5_0_4},
						    ]  ,)




		@require_torch
		def 							UpperCAmelCase_     (   self				)   ->		List[Any]:
						import torch

						lowerCAmelCase__			:  Optional[Any]											= pipeline(
						    task="""text-classification"""  ,model="""hf-internal-testing/tiny-random-distilbert"""  ,framework="""pt"""  ,device=torch.device("""cpu"""				)  ,)

						lowerCAmelCase__			:  Optional[Any]											= text_classifier("""This is great !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}]				)




		@require_tf
		def 							UpperCAmelCase_     (   self				)   ->		Any:
						lowerCAmelCase__			:  Optional[Any]											= pipeline(
						    task="""text-classification"""  ,model="""hf-internal-testing/tiny-random-distilbert"""  ,framework="""tf"""				)

						lowerCAmelCase__			:  List[Any]											= text_classifier("""This is great !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """LABEL_0""", """score""": 0.5_0_4}]				)




		@slow
		@require_torch
		def 							UpperCAmelCase_     (   self				)   ->		List[Any]:
						lowerCAmelCase__			:  Tuple											= pipeline("""text-classification"""				)

						lowerCAmelCase__			:  Union[str, Any]											= text_classifier("""This is great !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """POSITIVE""", """score""": 1.0}]				)
						lowerCAmelCase__			:  Optional[Any]											= text_classifier("""This is bad !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """NEGATIVE""", """score""": 1.0}]				)
						lowerCAmelCase__			:  List[str]											= text_classifier("""Birds are a type of animal"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """POSITIVE""", """score""": 0.9_8_8}]				)




		@slow
		@require_tf
		def 							UpperCAmelCase_     (   self				)   ->		Optional[Any]:
						lowerCAmelCase__			:  List[Any]											= pipeline("""text-classification"""  ,framework="""tf"""				)

						lowerCAmelCase__			:  Any											= text_classifier("""This is great !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """POSITIVE""", """score""": 1.0}]				)
						lowerCAmelCase__			:  Any											= text_classifier("""This is bad !"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """NEGATIVE""", """score""": 1.0}]				)
						lowerCAmelCase__			:  Union[str, Any]											= text_classifier("""Birds are a type of animal"""				)
						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": """POSITIVE""", """score""": 0.9_8_8}]				)




		def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		Dict:
						lowerCAmelCase__			:  Any											= TextClassificationPipeline(model=__UpperCAmelCase  ,tokenizer=__UpperCAmelCase				)
						return text_classifier, ["HuggingFace is in", "This is another test"]






		def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		List[str]:
						lowerCAmelCase__			:  Tuple											= text_classifier.model
						# Small inputs because BartTokenizer tiny has maximum position embeddings = 22
						lowerCAmelCase__			:  Tuple											= """HuggingFace is in"""
						lowerCAmelCase__			:  Union[str, Any]											= text_classifier(__UpperCAmelCase				)

						self.assertEqual(nested_simplify(__UpperCAmelCase				)  ,[{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}]				)
						self.assertTrue(outputs[0]["""label"""] in model.config.idalabel.values()				)

						lowerCAmelCase__			:  Tuple											= ["""HuggingFace is in """, """Paris is in France"""]
						lowerCAmelCase__			:  List[str]											= text_classifier(__UpperCAmelCase				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}, {"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}]  ,)
						self.assertTrue(outputs[0]["""label"""] in model.config.idalabel.values()				)
						self.assertTrue(outputs[1]["""label"""] in model.config.idalabel.values()				)

						# Forcing to get all results with `top_k=None`
						# This is NOT the legacy format
						lowerCAmelCase__			:  int											= text_classifier(__UpperCAmelCase  ,top_k=__UpperCAmelCase				)
						lowerCAmelCase__			:  List[Any]											= len(model.config.idalabel.values()				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[[{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}] * N, [{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}] * N]  ,)

						lowerCAmelCase__			:  List[str]											= {"""text""": """HuggingFace is in """, """text_pair""": """Paris is in France"""}
						lowerCAmelCase__			:  List[Any]											= text_classifier(__UpperCAmelCase				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}  ,)
						self.assertTrue(outputs["""label"""] in model.config.idalabel.values()				)

						# This might be used a text pair, but tokenizer + pipe interaction
						# makes it hard to understand that it's not using the pair properly
						# https://github.com/huggingface/transformers/issues/17305
						# We disabled this usage instead as it was outputting wrong outputs.
						lowerCAmelCase__			:  Optional[int]											= [["""HuggingFace is in """, """Paris is in France"""]]
						with self.assertRaises(__UpperCAmelCase				):
										text_classifier(__UpperCAmelCase				)

						# This used to be valid for doing text pairs
						# We're keeping it working because of backward compatibility
						lowerCAmelCase__			:  Tuple											= text_classifier([[["""HuggingFace is in """, """Paris is in France"""]]]				)
						self.assertEqual(
						    nested_simplify(__UpperCAmelCase				)  ,[{"""label""": ANY(__UpperCAmelCase				), """score""": ANY(__UpperCAmelCase				)}]  ,)
						self.assertTrue(outputs[0]["""label"""] in model.config.idalabel.values()				)







'''simple docstring'''





def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase = 1000      ):



    """simple docstring"""





    lowerCAmelCase__			:  Union[str, Any]											= -1
    lowerCAmelCase__			:  Optional[Any]											= 0
    for a in range(1							,   n // 3      ):
        # Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c
        lowerCAmelCase__			:  Optional[Any]											= (n * n - 2 * a * n) // (2 * n - 2 * a)
        lowerCAmelCase__			:  Tuple											= n - a - b
        if c * c == (a * a + b * b):
            lowerCAmelCase__			:  int											= a * b * c
            if candidate >= product:
                lowerCAmelCase__			:  Any											= candidate
    return product


if __name__ == "__main__":
 print(F"""{solution() = }""")


