"""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.
SCREAMING_SNAKE_CASE									=						{'LayoutLMv2Config', 'LayoutLMv3Config'}



@is_pipeline_test
class  _lowerCamelCase			(unittest.TestCase     ):
				_snake_case     =  MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
				_snake_case     =  TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

				if model_mapping is not None:
								_snake_case     =  {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
				if tf_model_mapping is not None:
								_snake_case     =  {
								    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
								}







				@require_torch
				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    Optional[Any]							=							pipeline(
					    task='text-classification'			,					model='hf-internal-testing/tiny-random-distilbert'			,					framework='pt'						)

					_lowercase :    Dict							=							text_classifier('This is great !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}]						)

					_lowercase :    Tuple							=							text_classifier('This is great !'			,					top_k=2						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}]						)

					_lowercase :    str							=							text_classifier(['This is great !', 'This is bad']			,					top_k=2						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[
					        [{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}],
					        [{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}],
					    ]			,					)

					_lowercase :    str							=							text_classifier('This is great !'			,					top_k=1						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}]						)

					# Legacy behavior
					_lowercase :    List[Any]							=							text_classifier('This is great !'			,					return_all_scores=lowerCamelCase_						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}]						)

					_lowercase :    Optional[Any]							=							text_classifier('This is great !'			,					return_all_scores=lowerCamelCase_						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[[{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}]]						)

					_lowercase :    Any							=							text_classifier(['This is great !', 'Something else']			,					return_all_scores=lowerCamelCase_						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[
					        [{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}],
					        [{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}],
					    ]			,					)

					_lowercase :    int							=							text_classifier(['This is great !', 'Something else']			,					return_all_scores=lowerCamelCase_						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[
					        {'label': 'LABEL_0', 'score': 0.504},
					        {'label': 'LABEL_0', 'score': 0.504},
					    ]			,					)







				@require_torch
				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					import torch

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

					_lowercase :    Optional[Any]							=							text_classifier('This is great !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}]						)







				@require_tf
				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    str							=							pipeline(
					    task='text-classification'			,					model='hf-internal-testing/tiny-random-distilbert'			,					framework='tf'						)

					_lowercase :    List[str]							=							text_classifier('This is great !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'LABEL_0', 'score': 0.504}]						)







				@slow
				@require_torch
				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    List[str]							=							pipeline('text-classification'						)

					_lowercase :    str							=							text_classifier('This is great !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'POSITIVE', 'score': 1.0}]						)
					_lowercase :    Optional[int]							=							text_classifier('This is bad !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'NEGATIVE', 'score': 1.0}]						)
					_lowercase :    Optional[Any]							=							text_classifier('Birds are a type of animal'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'POSITIVE', 'score': 0.988}]						)







				@slow
				@require_tf
				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    Tuple							=							pipeline('text-classification'			,					framework='tf'						)

					_lowercase :    Tuple							=							text_classifier('This is great !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'POSITIVE', 'score': 1.0}]						)
					_lowercase :    str							=							text_classifier('This is bad !'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'NEGATIVE', 'score': 1.0}]						)
					_lowercase :    List[Any]							=							text_classifier('Birds are a type of animal'						)
					self.assertEqual(nested_simplify(lowerCamelCase_						)			,					[{'label': 'POSITIVE', 'score': 0.988}]						)







				def 							__UpperCAmelCase					( self    :       Union[str, Any]			,					lowerCamelCase_    :       Optional[Any]			,					lowerCamelCase_    :       Any			,					lowerCamelCase_    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    str							=							TextClassificationPipeline(model=lowerCamelCase_			,					tokenizer=lowerCamelCase_						)
					return text_classifier, ["HuggingFace is in", "This is another test"]







				def 							__UpperCAmelCase					( self    :       str			,					lowerCamelCase_    :       Any			,					lowerCamelCase_    :       int						):

					"""simple docstring"""






					_lowercase :    Any							=							text_classifier.model
					# Small inputs because BartTokenizer tiny has maximum position embeddings = 22
					_lowercase :    Dict							=							'HuggingFace is in'
					_lowercase :    Optional[int]							=							text_classifier(lowerCamelCase_						)

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

					_lowercase :    Dict							=							['HuggingFace is in ', 'Paris is in France']
					_lowercase :    Optional[int]							=							text_classifier(lowerCamelCase_						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[{'label': ANY(lowerCamelCase_						), 'score': ANY(lowerCamelCase_						)}, {'label': ANY(lowerCamelCase_						), 'score': ANY(lowerCamelCase_						)}]			,					)
					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
					_lowercase :    List[str]							=							text_classifier(lowerCamelCase_			,					top_k=lowerCamelCase_						)
					_lowercase :    str							=							len(model.config.idalabel.values()						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					[[{'label': ANY(lowerCamelCase_						), 'score': ANY(lowerCamelCase_						)}] * N, [{'label': ANY(lowerCamelCase_						), 'score': ANY(lowerCamelCase_						)}] * N]			,					)

					_lowercase :    str							=							{'text': 'HuggingFace is in ', 'text_pair': 'Paris is in France'}
					_lowercase :    int							=							text_classifier(lowerCamelCase_						)
					self.assertEqual(
					    nested_simplify(lowerCamelCase_						)			,					{'label': ANY(lowerCamelCase_						), 'score': ANY(lowerCamelCase_						)}			,					)
					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.
					_lowercase :    Dict							=							[['HuggingFace is in ', 'Paris is in France']]
					with self.assertRaises(lowerCamelCase_						):
						text_classifier(lowerCamelCase_						)

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




"""simple docstring"""







from __future__ import annotations


def      __lowerCAmelCase(		__UpperCAmelCase			):






	"""simple docstring"""





	_lowercase :    Any							=							[True] * limit
	_lowercase :    Union[str, Any]							=							False
	_lowercase :    Any							=							False
	_lowercase :    List[Any]							=							True

	for i in range(3     ,int(limit**0.5 + 1			)     ,2			):
		_lowercase :    Optional[Any]							=							i * 2
		while index < limit:
			_lowercase :    int							=							False
			_lowercase :    Tuple							=							index + i

	_lowercase :    Optional[Any]							=							[2]

	for i in range(3     ,__UpperCAmelCase     ,2			):
		if is_prime[i]:
			primes.append(__UpperCAmelCase			)

	return primes


def      __lowerCAmelCase(		__UpperCAmelCase = 1_000_000			):






	"""simple docstring"""





	_lowercase :    Optional[Any]							=							prime_sieve(__UpperCAmelCase			)
	_lowercase :    int							=							0
	_lowercase :    List[Any]							=							0

	for i in range(len(__UpperCAmelCase			)			):
		for j in range(i + length     ,len(__UpperCAmelCase			)			):
			_lowercase :    List[Any]							=							sum(primes[i:j]			)
			if sol >= ceiling:
				break

			if sol in primes:
				_lowercase :    Optional[int]							=							j - i
				_lowercase :    Tuple							=							sol

	return largest


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



