


import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
   from PIL import Image

   from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
   import torch

if is_tf_available():
   import tensorflow as tf
@require_vision
@require_torchvision
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Optional[int]:
             a_					:		Optional[Any]							=  tempfile.mkdtemp()
             a_					:		Any							=  SamImageProcessor()
             a_					:		int							=  SamProcessor(SCREAMING_SNAKE_CASE__     )
             processor.save_pretrained(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       str     ,							**SCREAMING_SNAKE_CASE__				:       Any     )		->			Dict:
             return AutoProcessor.from_pretrained(self.tmpdirname     ,							**SCREAMING_SNAKE_CASE__     ).image_processor
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Dict:
             shutil.rmtree(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Optional[Any]:
             a_					:		Tuple							=  [np.random.randint(2_5_5     ,							size=(3, 3_0, 4_0_0)     ,							dtype=np.uinta     )]

             a_					:		List[Any]							=  [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE__     ,							0     ,							-1     )     ) for x in image_inputs]

             return image_inputs
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Union[str, Any]:
             a_					:		Dict							=  SamProcessor(image_processor=self.get_image_processor()     )
             processor.save_pretrained(self.tmpdirname     )

             a_					:		Tuple							=  self.get_image_processor(do_normalize=SCREAMING_SNAKE_CASE__     ,							padding_value=1.0     )

             a_					:		List[str]							=  SamProcessor.from_pretrained(self.tmpdirname     ,							do_normalize=SCREAMING_SNAKE_CASE__     ,							padding_value=1.0     )

             self.assertEqual(processor.image_processor.to_json_string()     ,							image_processor_add_kwargs.to_json_string()     )
             self.assertIsInstance(processor.image_processor     ,							SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Tuple:
             a_					:		Tuple							=  self.get_image_processor()

             a_					:		Union[str, Any]							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )

             a_					:		Union[str, Any]							=  self.prepare_image_inputs()

             a_					:		Union[str, Any]							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='np'     )
             a_					:		int							=  processor(images=SCREAMING_SNAKE_CASE__     ,							return_tensors='np'     )

             input_feat_extract.pop('original_sizes'     )  # pop original_sizes as it is popped in the processor
             input_feat_extract.pop('reshaped_input_sizes'     )  # pop original_sizes as it is popped in the processor

             for key in input_feat_extract.keys():
                    self.assertAlmostEqual(input_feat_extract[key].sum()     ,							input_processor[key].sum()     ,							delta=1E-2     )

      @require_torch
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			List[Any]:
             a_					:		Optional[Any]							=  self.get_image_processor()

             a_					:		str							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )
             a_					:		str							=  [torch.ones((1, 3, 5, 5)     )]

             a_					:		List[Any]							=  [[1_7_6_4, 2_6_4_6]]

             a_					:		Optional[int]							=  [[6_8_3, 1_0_2_4]]
             a_					:		Any							=  processor.post_process_masks(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             a_					:		List[str]							=  processor.post_process_masks(
                 SCREAMING_SNAKE_CASE__     ,							torch.tensor(SCREAMING_SNAKE_CASE__     )     ,							torch.tensor(SCREAMING_SNAKE_CASE__     )     )
             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             # should also work with np
             a_					:		Optional[Any]							=  [np.ones((1, 3, 5, 5)     )]
             a_					:		List[Any]							=  processor.post_process_masks(SCREAMING_SNAKE_CASE__     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							np.array(SCREAMING_SNAKE_CASE__     )     )

             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             a_					:		Optional[int]							=  [[1, 0], [0, 1]]
             with self.assertRaises(SCREAMING_SNAKE_CASE__     ):
                    a_					:		Tuple							=  processor.post_process_masks(SCREAMING_SNAKE_CASE__     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							np.array(SCREAMING_SNAKE_CASE__     )     )
@require_vision
@require_tf
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Any:
             a_					:		Any							=  tempfile.mkdtemp()
             a_					:		str							=  SamImageProcessor()
             a_					:		Dict							=  SamProcessor(SCREAMING_SNAKE_CASE__     )
             processor.save_pretrained(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     ,							**SCREAMING_SNAKE_CASE__				:       Dict     )		->			List[Any]:
             return AutoProcessor.from_pretrained(self.tmpdirname     ,							**SCREAMING_SNAKE_CASE__     ).image_processor
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			str:
             shutil.rmtree(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			List[Any]:
             a_					:		Optional[Any]							=  [np.random.randint(2_5_5     ,							size=(3, 3_0, 4_0_0)     ,							dtype=np.uinta     )]

             a_					:		Optional[int]							=  [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE__     ,							0     ,							-1     )     ) for x in image_inputs]

             return image_inputs
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			str:
             a_					:		List[str]							=  SamProcessor(image_processor=self.get_image_processor()     )
             processor.save_pretrained(self.tmpdirname     )

             a_					:		Union[str, Any]							=  self.get_image_processor(do_normalize=SCREAMING_SNAKE_CASE__     ,							padding_value=1.0     )

             a_					:		Tuple							=  SamProcessor.from_pretrained(self.tmpdirname     ,							do_normalize=SCREAMING_SNAKE_CASE__     ,							padding_value=1.0     )

             self.assertEqual(processor.image_processor.to_json_string()     ,							image_processor_add_kwargs.to_json_string()     )
             self.assertIsInstance(processor.image_processor     ,							SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Dict:
             a_					:		Optional[int]							=  self.get_image_processor()

             a_					:		Optional[int]							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )

             a_					:		List[str]							=  self.prepare_image_inputs()

             a_					:		str							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='np'     )
             a_					:		List[str]							=  processor(images=SCREAMING_SNAKE_CASE__     ,							return_tensors='np'     )

             input_feat_extract.pop('original_sizes'     )  # pop original_sizes as it is popped in the processor
             input_feat_extract.pop('reshaped_input_sizes'     )  # pop reshaped_input_sizes as it is popped in the processor

             for key in input_feat_extract.keys():
                    self.assertAlmostEqual(input_feat_extract[key].sum()     ,							input_processor[key].sum()     ,							delta=1E-2     )

      @require_tf
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[int]:
             a_					:		Optional[int]							=  self.get_image_processor()

             a_					:		List[Any]							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )
             a_					:		Union[str, Any]							=  [tf.ones((1, 3, 5, 5)     )]

             a_					:		List[Any]							=  [[1_7_6_4, 2_6_4_6]]

             a_					:		int							=  [[6_8_3, 1_0_2_4]]
             a_					:		Optional[int]							=  processor.post_process_masks(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							return_tensors='tf'     )
             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             a_					:		Optional[Any]							=  processor.post_process_masks(
                 SCREAMING_SNAKE_CASE__     ,							tf.convert_to_tensor(SCREAMING_SNAKE_CASE__     )     ,							tf.convert_to_tensor(SCREAMING_SNAKE_CASE__     )     ,							return_tensors='tf'     ,							)
             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             # should also work with np
             a_					:		Tuple							=  [np.ones((1, 3, 5, 5)     )]
             a_					:		Any							=  processor.post_process_masks(
                 SCREAMING_SNAKE_CASE__     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							return_tensors='tf'     )

             self.assertEqual(masks[0].shape     ,							(1, 3, 1_7_6_4, 2_6_4_6)     )

             a_					:		Any							=  [[1, 0], [0, 1]]
             with self.assertRaises(tf.errors.InvalidArgumentError     ):
                    a_					:		List[Any]							=  processor.post_process_masks(
                        SCREAMING_SNAKE_CASE__     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							np.array(SCREAMING_SNAKE_CASE__     )     ,							return_tensors='tf'     )
@require_vision
@require_torchvision
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Any:
             a_					:		List[str]							=  tempfile.mkdtemp()
             a_					:		Tuple							=  SamImageProcessor()
             a_					:		Optional[int]							=  SamProcessor(SCREAMING_SNAKE_CASE__     )
             processor.save_pretrained(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       int     ,							**SCREAMING_SNAKE_CASE__				:       str     )		->			Union[str, Any]:
             return AutoProcessor.from_pretrained(self.tmpdirname     ,							**SCREAMING_SNAKE_CASE__     ).image_processor
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			int:
             shutil.rmtree(self.tmpdirname     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Dict:
             a_					:		Optional[int]							=  [np.random.randint(2_5_5     ,							size=(3, 3_0, 4_0_0)     ,							dtype=np.uinta     )]

             a_					:		int							=  [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE__     ,							0     ,							-1     )     ) for x in image_inputs]

             return image_inputs
      @is_pt_tf_cross_test
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			List[Any]:
             a_					:		Optional[Any]							=  self.get_image_processor()

             a_					:		Tuple							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )
             a_					:		List[str]							=  np.random.randint(0     ,							2     ,							size=(1, 3, 5, 5)     ).astype(np.floataa     )
             a_					:		Any							=  [tf.convert_to_tensor(SCREAMING_SNAKE_CASE__     )]
             a_					:		Dict							=  [torch.tensor(SCREAMING_SNAKE_CASE__     )]

             a_					:		Any							=  [[1_7_6_4, 2_6_4_6]]

             a_					:		List[str]							=  [[6_8_3, 1_0_2_4]]
             a_					:		int							=  processor.post_process_masks(
                 SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							return_tensors='tf'     )
             a_					:		str							=  processor.post_process_masks(
                 SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							return_tensors='pt'     )

             self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()     )     )

      @is_pt_tf_cross_test
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			List[Any]:
             a_					:		Any							=  self.get_image_processor()

             a_					:		Any							=  SamProcessor(image_processor=SCREAMING_SNAKE_CASE__     )

             a_					:		str							=  self.prepare_image_inputs()

             a_					:		Optional[Any]							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='pt'     )['pixel_values'].numpy()
             a_					:		Dict							=  processor(images=SCREAMING_SNAKE_CASE__     ,							return_tensors='pt'     )['pixel_values'].numpy()

             a_					:		Optional[int]							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='tf'     )['pixel_values'].numpy()
             a_					:		List[Any]							=  processor(images=SCREAMING_SNAKE_CASE__     ,							return_tensors='tf'     )['pixel_values'].numpy()

             self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )     )
             self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )     )
             self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )     )






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.
UpperCAmelCase_      : Dict  					=       {'LayoutLMv2Config', 'LayoutLMv3Config'}
@is_pipeline_test
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      snake_case__				:     List[str]        =						MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
      snake_case__				:     Optional[Any]        =						TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

      if model_mapping is not None:
            snake_case__				:     str        =						{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__				:     List[Any]        =						{
                config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
            }
      @require_torch
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Tuple:
             a_					:		List[Any]							=  pipeline(
                 task='text-classification'     ,							model='hf-internal-testing/tiny-random-distilbert'     ,							framework='pt'     )

             a_					:		int							=  text_classifier('This is great !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'LABEL_0', 'score': 0.504}]     )

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

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

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

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

             a_					:		List[str]							=  text_classifier('This is great !'     ,							return_all_scores=SCREAMING_SNAKE_CASE__     )
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[[{'label': 'LABEL_0', 'score': 0.504}, {'label': 'LABEL_1', 'score': 0.496}]]     )

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

             a_					:		str							=  text_classifier(['This is great !', 'Something else']     ,							return_all_scores=SCREAMING_SNAKE_CASE__     )
             self.assertEqual(
                 nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[
                     {'label': 'LABEL_0', 'score': 0.504},
                     {'label': 'LABEL_0', 'score': 0.504},
                 ]     ,							)
      @require_torch
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			Dict:
             import torch

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

             a_					:		Any							=  text_classifier('This is great !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'LABEL_0', 'score': 0.504}]     )
      @require_tf
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		List[str]							=  pipeline(
                 task='text-classification'     ,							model='hf-internal-testing/tiny-random-distilbert'     ,							framework='tf'     )

             a_					:		Optional[int]							=  text_classifier('This is great !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'LABEL_0', 'score': 0.504}]     )
      @slow
      @require_torch
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			Optional[int]:
             a_					:		List[str]							=  pipeline('text-classification'     )

             a_					:		Dict							=  text_classifier('This is great !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'POSITIVE', 'score': 1.0}]     )
             a_					:		Union[str, Any]							=  text_classifier('This is bad !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'NEGATIVE', 'score': 1.0}]     )
             a_					:		Tuple							=  text_classifier('Birds are a type of animal'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'POSITIVE', 'score': 0.988}]     )
      @slow
      @require_tf
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			List[Any]:
             a_					:		Dict							=  pipeline('text-classification'     ,							framework='tf'     )

             a_					:		Optional[Any]							=  text_classifier('This is great !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'POSITIVE', 'score': 1.0}]     )
             a_					:		int							=  text_classifier('This is bad !'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'NEGATIVE', 'score': 1.0}]     )
             a_					:		Optional[int]							=  text_classifier('Birds are a type of animal'     )
             self.assertEqual(nested_simplify(SCREAMING_SNAKE_CASE__     )     ,							[{'label': 'POSITIVE', 'score': 0.988}]     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]     )		->			Any:
             a_					:		Optional[Any]							=  TextClassificationPipeline(model=SCREAMING_SNAKE_CASE__     ,							tokenizer=SCREAMING_SNAKE_CASE__     )
             return text_classifier, ["HuggingFace is in", "This is another test"]

      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     )		->			Union[str, Any]:
             a_					:		List[str]							=  text_classifier.model
             # Small inputs because BartTokenizer tiny has maximum position embeddings = 22
             a_					:		Union[str, Any]							=  'HuggingFace is in'
             a_					:		int							=  text_classifier(SCREAMING_SNAKE_CASE__     )

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

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

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

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


