


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






@is_pipeline_test
class 		_snake_case     (					unittest.TestCase		):






						'''simple docstring'''







						__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 lowerCAmelCase__			(	self:						Dict  )				->						Union[str, Any]:
										__magic_name__					:       Tuple    							=							pipeline(
										    task="text-classification"   ,				model="hf-internal-testing/tiny-random-distilbert"   ,				framework="pt"  )

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

										__magic_name__					:       List[Any]    							=							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}]  )

										__magic_name__					:       Optional[Any]    							=							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}],
										    ]   ,				)

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

										# Legacy behavior
										__magic_name__					:       List[str]    							=							text_classifier("This is great !"   ,				return_all_scores=__UpperCamelCase  )
										self.assertEqual(nested_simplify(__UpperCamelCase  )   ,				[{"label": "LABEL_0", "score": 0.5_0_4}]  )

										__magic_name__					:       int    							=							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}]]  )

										__magic_name__					:       Any    							=							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}],
										    ]   ,				)

										__magic_name__					:       Optional[Any]    							=							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 lowerCAmelCase__			(	self:						List[str]  )				->						Optional[int]:
										import torch

										__magic_name__					:       Dict    							=							pipeline(
										    task="text-classification"   ,				model="hf-internal-testing/tiny-random-distilbert"   ,				framework="pt"   ,				device=torch.device("cpu"  )   ,				)

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







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

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







						@slow
						@require_torch
						def lowerCAmelCase__			(	self:						Optional[int]  )				->						str:
										__magic_name__					:       int    							=							pipeline("text-classification"  )

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







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

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







						def lowerCAmelCase__			(	self:						Optional[Any]   ,				__UpperCamelCase:						Union[str, Any]   ,				__UpperCamelCase:						Optional[int]   ,				__UpperCamelCase:						Optional[Any]  )				->						int:
										__magic_name__					:       Optional[Any]    							=							TextClassificationPipeline(model=__UpperCamelCase   ,				tokenizer=__UpperCamelCase  )
										return text_classifier, ["HuggingFace is in", "This is another test"]







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

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

										__magic_name__					:       Optional[int]    							=							["HuggingFace is in ", "Paris is in France"]
										__magic_name__					:       int    							=							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
										__magic_name__					:       str    							=							text_classifier(__UpperCamelCase   ,				top_k=__UpperCamelCase  )
										__magic_name__					:       Optional[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]   ,				)

										__magic_name__					:       Optional[Any]    							=							{"text": "HuggingFace is in ", "text_pair": "Paris is in France"}
										__magic_name__					:       Dict    							=							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.
										__magic_name__					:       Union[str, Any]    							=							[["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
										__magic_name__					:       Union[str, Any]    							=							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()  )

import warnings

from ...utils import logging
from .image_processing_yolos import YolosImageProcessor


__lowerCAmelCase					   =       logging.get_logger(__name__)





class     lowerCamelCase      (       __lowerCamelCase					):







	def __init__(     self      :List[Any]   ,     *lowercase      :List[str]   ,     **lowercase      :List[Any]			)		->      None:







				"""simple docstring"""






				warnings.warn(
				    '''The class YolosFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'''
				    ''' use YolosImageProcessor instead.'''   ,     lowercase   ,     )
				super().__init__(*lowercase   ,     **lowercase			)