





from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers import (
           TFFunnelBaseModel,
           TFFunnelForMaskedLM,
           TFFunnelForMultipleChoice,
           TFFunnelForPreTraining,
           TFFunnelForQuestionAnswering,
           TFFunnelForSequenceClassification,
           TFFunnelForTokenClassification,
           TFFunnelModel,
       )

class    lowerCAmelCase_		:




 def __init__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase=13			,     _lowerCAmelCase=7			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=99			,     _lowerCAmelCase=[1, 1, 2]			,     _lowerCAmelCase=1			,     _lowerCAmelCase=32			,     _lowerCAmelCase=4			,     _lowerCAmelCase=8			,     _lowerCAmelCase=37			,     _lowerCAmelCase="gelu_new"			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=0.0			,     _lowerCAmelCase=512			,     _lowerCAmelCase=3			,     _lowerCAmelCase=0.02			,     _lowerCAmelCase=3			,     _lowerCAmelCase=4			,     _lowerCAmelCase=None			,     _lowerCAmelCase=False			,     )    ->							str:
     _lowerCAmelCase				=      parent
     _lowerCAmelCase				=      batch_size
     _lowerCAmelCase				=      seq_length
     _lowerCAmelCase				=      is_training
     _lowerCAmelCase				=      use_input_mask
     _lowerCAmelCase				=      use_token_type_ids
     _lowerCAmelCase				=      use_labels
     _lowerCAmelCase				=      vocab_size
     _lowerCAmelCase				=      block_sizes
     _lowerCAmelCase				=      num_decoder_layers
     _lowerCAmelCase				=      d_model
     _lowerCAmelCase				=      n_head
     _lowerCAmelCase				=      d_head
     _lowerCAmelCase				=      d_inner
     _lowerCAmelCase				=      hidden_act
     _lowerCAmelCase				=      hidden_dropout
     _lowerCAmelCase				=      attention_dropout
     _lowerCAmelCase				=      activation_dropout
     _lowerCAmelCase				=      max_position_embeddings
     _lowerCAmelCase				=      type_vocab_size
     _lowerCAmelCase				=      2
     _lowerCAmelCase				=      num_labels
     _lowerCAmelCase				=      num_choices
     _lowerCAmelCase				=      scope
     _lowerCAmelCase				=      initializer_std

     # Used in the tests to check the size of the first attention layer
     _lowerCAmelCase				=      n_head
     # Used in the tests to check the size of the first hidden state
     _lowerCAmelCase				=      self.d_model
     # Used in the tests to check the number of output hidden states/attentions
     _lowerCAmelCase				=      sum(self.block_sizes		) + (0 if base else self.num_decoder_layers)
     # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
     # the last hidden state of the first block (which is the first hidden state of the decoder).
     if not base:
         _lowerCAmelCase				=      self.num_hidden_layers + 2




 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size		)

     _lowerCAmelCase				=      None
     if self.use_input_mask:
         _lowerCAmelCase				=      random_attention_mask([self.batch_size, self.seq_length]		)

     _lowerCAmelCase				=      None
     if self.use_token_type_ids:
         _lowerCAmelCase				=      ids_tensor([self.batch_size, self.seq_length]			,     self.type_vocab_size		)

     _lowerCAmelCase				=      None
     _lowerCAmelCase				=      None
     _lowerCAmelCase				=      None
     if self.use_labels:
         _lowerCAmelCase				=      ids_tensor([self.batch_size]			,     self.type_sequence_label_size		)
         _lowerCAmelCase				=      ids_tensor([self.batch_size, self.seq_length]			,     self.num_labels		)
         _lowerCAmelCase				=      ids_tensor([self.batch_size]			,     self.num_choices		)

     _lowerCAmelCase				=      FunnelConfig(
         vocab_size=self.vocab_size			,     block_sizes=self.block_sizes			,     num_decoder_layers=self.num_decoder_layers			,     d_model=self.d_model			,     n_head=self.n_head			,     d_head=self.d_head			,     d_inner=self.d_inner			,     hidden_act=self.hidden_act			,     hidden_dropout=self.hidden_dropout			,     attention_dropout=self.attention_dropout			,     activation_dropout=self.activation_dropout			,     max_position_embeddings=self.max_position_embeddings			,     type_vocab_size=self.type_vocab_size			,     initializer_std=self.initializer_std			,     )

     return (
         config,
         input_ids,
         token_type_ids,
         input_mask,
         sequence_labels,
         token_labels,
         choice_labels,
     )




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Optional[Any]:
     _lowerCAmelCase				=      TFFunnelModel(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)

     _lowerCAmelCase				=      [input_ids, input_mask]
     _lowerCAmelCase				=      model(__A		)

     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.d_model)		)

     _lowerCAmelCase				=      False
     _lowerCAmelCase				=      TFFunnelModel(config=__A		)
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.d_model)		)

     _lowerCAmelCase				=      False
     _lowerCAmelCase				=      TFFunnelModel(config=__A		)
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.seq_length, self.d_model)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Any:
     _lowerCAmelCase				=      TFFunnelBaseModel(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)

     _lowerCAmelCase				=      [input_ids, input_mask]
     _lowerCAmelCase				=      model(__A		)

     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, 2, self.d_model)		)

     _lowerCAmelCase				=      False
     _lowerCAmelCase				=      TFFunnelBaseModel(config=__A		)
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, 3, self.d_model)		)

     _lowerCAmelCase				=      False
     _lowerCAmelCase				=      TFFunnelBaseModel(config=__A		)
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, 2, self.d_model)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Optional[int]:
     _lowerCAmelCase				=      TFFunnelForPreTraining(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.seq_length)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Union[str, Any]:
     _lowerCAmelCase				=      TFFunnelForMaskedLM(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.seq_length, self.vocab_size)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Any:
     _lowerCAmelCase				=      self.num_labels
     _lowerCAmelCase				=      TFFunnelForSequenceClassification(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Tuple:
     _lowerCAmelCase				=      self.num_choices
     _lowerCAmelCase				=      TFFunnelForMultipleChoice(config=__A		)
     _lowerCAmelCase				=      tf.tile(tf.expand_dims(__A			,     1		)			,     (1, self.num_choices, 1)		)
     _lowerCAmelCase				=      tf.tile(tf.expand_dims(__A			,     1		)			,     (1, self.num_choices, 1)		)
     _lowerCAmelCase				=      tf.tile(tf.expand_dims(__A			,     1		)			,     (1, self.num_choices, 1)		)
     _lowerCAmelCase				=      {
         "input_ids": multiple_choice_inputs_ids,
         "attention_mask": multiple_choice_input_mask,
         "token_type_ids": multiple_choice_token_type_ids,
     }
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_choices)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Tuple:
     _lowerCAmelCase				=      self.num_labels
     _lowerCAmelCase				=      TFFunnelForTokenClassification(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.seq_length, self.num_labels)		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase			,     )    ->							Tuple:
     _lowerCAmelCase				=      TFFunnelForQuestionAnswering(config=__A		)
     _lowerCAmelCase				=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     _lowerCAmelCase				=      model(__A		)
     self.parent.assertEqual(result.start_logits.shape			,     (self.batch_size, self.seq_length)		)
     self.parent.assertEqual(result.end_logits.shape			,     (self.batch_size, self.seq_length)		)





 def 							_snake_case   (	self		)    ->							int:
     _lowerCAmelCase				=      self.prepare_config_and_inputs()
     (
         (
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,			(
         _lowerCAmelCase				
     )			,							
     )				=      config_and_inputs
     _lowerCAmelCase				=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
     return config, inputs_dict







@require_tf
class    lowerCAmelCase_		(		__lowercase						,__lowercase						,unittest.TestCase		):
 __lowerCamelCase						:							Tuple         =					(
     (
         TFFunnelModel,
         TFFunnelForMaskedLM,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForTokenClassification,
     )
     if is_tf_available()
     else ()
 )
 __lowerCamelCase						:							Union[str, Any]         =					(
     {
         'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
         'fill-mask': TFFunnelForMaskedLM,
         'question-answering': TFFunnelForQuestionAnswering,
         'text-classification': TFFunnelForSequenceClassification,
         'token-classification': TFFunnelForTokenClassification,
         'zero-shot': TFFunnelForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __lowerCamelCase						:							Tuple         =					False
 __lowerCamelCase						:							Union[str, Any]         =					False




 def 							_snake_case   (	self		)    ->							Dict:
     _lowerCAmelCase				=      TFFunnelModelTester(self		)
     _lowerCAmelCase				=      ConfigTester(self			,     config_class=__A		)




 def 							_snake_case   (	self		)    ->							List[str]:
     self.config_tester.run_common_tests()




 def 							_snake_case   (	self		)    ->							Optional[Any]:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__A		)




 def 							_snake_case   (	self		)    ->							List[Any]:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*__A		)




 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*__A		)




 def 							_snake_case   (	self		)    ->							List[str]:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*__A		)





 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*__A		)







@require_tf
class    lowerCAmelCase_		(		__lowercase						,unittest.TestCase		):
 __lowerCamelCase						:							Tuple         =					(
     (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
 )
 __lowerCamelCase						:							List[Any]         =					False
 __lowerCamelCase						:							Optional[Any]         =					False




 def 							_snake_case   (	self		)    ->							Optional[int]:
     _lowerCAmelCase				=      TFFunnelModelTester(self			,     base=__A		)
     _lowerCAmelCase				=      ConfigTester(self			,     config_class=__A		)




 def 							_snake_case   (	self		)    ->							Optional[Any]:
     self.config_tester.run_common_tests()




 def 							_snake_case   (	self		)    ->							int:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_base_model(*__A		)




 def 							_snake_case   (	self		)    ->							List[str]:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*__A		)





 def 							_snake_case   (	self		)    ->							List[Any]:
     _lowerCAmelCase				=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*__A		)









'''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		):
 __lowerCamelCase						:							Optional[Any]         =					MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
 __lowerCamelCase						:							str         =					TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

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




 @require_torch
 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      pipeline(
         task="text-classification"			,     model="hf-internal-testing/tiny-random-distilbert"			,     framework="pt"		)

     _lowerCAmelCase				=      text_classifier("This is great !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "LABEL_0", "score": 0.504}]		)

     _lowerCAmelCase				=      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}]		)

     _lowerCAmelCase				=      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}],
         ]			,     )

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

     # Legacy behavior
     _lowerCAmelCase				=      text_classifier("This is great !"			,     return_all_scores=_lowerCAmelCase		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "LABEL_0", "score": 0.504}]		)

     _lowerCAmelCase				=      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}]]		)

     _lowerCAmelCase				=      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}],
         ]			,     )

     _lowerCAmelCase				=      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 							_snake_case   (	self		)    ->							Tuple:
     import torch

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

     _lowerCAmelCase				=      text_classifier("This is great !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "LABEL_0", "score": 0.504}]		)




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

     _lowerCAmelCase				=      text_classifier("This is great !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "LABEL_0", "score": 0.504}]		)




 @slow
 @require_torch
 def 							_snake_case   (	self		)    ->							Dict:
     _lowerCAmelCase				=      pipeline("text-classification"		)

     _lowerCAmelCase				=      text_classifier("This is great !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "POSITIVE", "score": 1.0}]		)
     _lowerCAmelCase				=      text_classifier("This is bad !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "NEGATIVE", "score": 1.0}]		)
     _lowerCAmelCase				=      text_classifier("Birds are a type of animal"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "POSITIVE", "score": 0.988}]		)




 @slow
 @require_tf
 def 							_snake_case   (	self		)    ->							Any:
     _lowerCAmelCase				=      pipeline("text-classification"			,     framework="tf"		)

     _lowerCAmelCase				=      text_classifier("This is great !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "POSITIVE", "score": 1.0}]		)
     _lowerCAmelCase				=      text_classifier("This is bad !"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "NEGATIVE", "score": 1.0}]		)
     _lowerCAmelCase				=      text_classifier("Birds are a type of animal"		)
     self.assertEqual(nested_simplify(_lowerCAmelCase		)			,     [{"label": "POSITIVE", "score": 0.988}]		)




 def 							_snake_case   (	self			,     _lowerCAmelCase			,     _lowerCAmelCase			,     _lowerCAmelCase		)    ->							str:
     _lowerCAmelCase				=      TextClassificationPipeline(model=_lowerCAmelCase			,     tokenizer=_lowerCAmelCase		)
     return text_classifier, ["HuggingFace is in", "This is another test"]





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

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

     _lowerCAmelCase				=      ["HuggingFace is in ", "Paris is in France"]
     _lowerCAmelCase				=      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
     _lowerCAmelCase				=      text_classifier(_lowerCAmelCase			,     top_k=_lowerCAmelCase		)
     _lowerCAmelCase				=      len(model.config.idalabel.values()		)
     self.assertEqual(
         nested_simplify(_lowerCAmelCase		)			,     [[{"label": ANY(_lowerCAmelCase		), "score": ANY(_lowerCAmelCase		)}] * N, [{"label": ANY(_lowerCAmelCase		), "score": ANY(_lowerCAmelCase		)}] * N]			,     )

     _lowerCAmelCase				=      {"text": "HuggingFace is in ", "text_pair": "Paris is in France"}
     _lowerCAmelCase				=      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.
     _lowerCAmelCase				=      [["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
     _lowerCAmelCase				=      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()		)


