



import os
from pathlib import Path

import numpy as np
import pytest
from pack_dataset import pack_data_dir
from parameterized import parameterized
from save_len_file import save_len_file
from torch.utils.data import DataLoader

from transformers import AutoTokenizer
from transformers.models.mbart.modeling_mbart import shift_tokens_right
from transformers.testing_utils import TestCasePlus, slow
from utils import FAIRSEQ_AVAILABLE, DistributedSortishSampler, LegacySeqaSeqDataset, SeqaSeqDataset


__A   			='bert-base-cased'
__A   			='google/pegasus-xsum'
__A   			=[' Sam ate lunch today.', 'Sams lunch ingredients.']
__A   			=['A very interesting story about what I ate for lunch.', 'Avocado, celery, turkey, coffee']
__A   			='patrickvonplaten/t5-tiny-random'
__A   			='sshleifer/bart-tiny-random'
__A   			='sshleifer/tiny-mbart'
__A   			='sshleifer/tiny-marian-en-de'

def        a						(      _UpperCAmelCase							:					Path ,   _UpperCAmelCase							:					list						):







		'''simple docstring'''





		__UpperCAmelCase    :     List[str]													=	'\n'.join(__A						)
		Path(__A						).open('''w'''						).writelines(__A						)

def        a						(      _UpperCAmelCase							:					Dict						):







		'''simple docstring'''





		for split in ["train", "val", "test"]:
				_dump_articles(os.path.join(__A ,   f'{split}.source'						) ,   __A						)
				_dump_articles(os.path.join(__A ,   f'{split}.target'						) ,   __A						)
		return tmp_dir

class 		UpperCAmelCase__			(			lowercase__   ):




			'''simple docstring'''






			@parameterized.expand(
			    [
			        MBART_TINY,
			        MARIAN_TINY,
			        T5_TINY,
			        BART_TINY,
			        PEGASUS_XSUM,
			    ]       ,       )
			@slow
			def  snake_case__     (   self							: int       ,       a_							: Union[str, Any] ):
					'''simple docstring'''





					__UpperCAmelCase    :     Any													=	AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__ )
					__UpperCAmelCase    :     Union[str, Any]													=	make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() )
					__UpperCAmelCase    :     Any													=	max(len(tokenizer.encode(SCREAMING_SNAKE_CASE__ ) ) for a in ARTICLES )
					__UpperCAmelCase    :     Tuple													=	max(len(tokenizer.encode(SCREAMING_SNAKE_CASE__ ) ) for a in SUMMARIES )
					__UpperCAmelCase    :     Optional[Any]													=	4
					__UpperCAmelCase    :     str													=	8
					assert max_len_target > max_src_len  # Will be truncated
					assert max_len_source > max_src_len  # Will be truncated
					__UpperCAmelCase    :     str													=	'ro_RO', 'de_DE'  # ignored for all but mbart, but never causes error.
					__UpperCAmelCase    :     str													=	SeqaSeqDataset(
					    SCREAMING_SNAKE_CASE__       ,       data_dir=SCREAMING_SNAKE_CASE__       ,       type_path='''train'''       ,       max_source_length=SCREAMING_SNAKE_CASE__       ,       max_target_length=SCREAMING_SNAKE_CASE__       ,       src_lang=SCREAMING_SNAKE_CASE__       ,       tgt_lang=SCREAMING_SNAKE_CASE__       ,       )
					__UpperCAmelCase    :     Tuple													=	DataLoader(SCREAMING_SNAKE_CASE__       ,       batch_size=2       ,       collate_fn=train_dataset.collate_fn )
					for batch in dataloader:
							assert isinstance(SCREAMING_SNAKE_CASE__       ,       SCREAMING_SNAKE_CASE__ )
							assert batch["attention_mask"].shape == batch["input_ids"].shape
							# show that articles were trimmed.
							assert batch["input_ids"].shape[1] == max_src_len
							# show that targets are the same len
							assert batch["labels"].shape[1] == max_tgt_len
							if tok_name != MBART_TINY:
									continue
							# check language codes in correct place
							__UpperCAmelCase    :     Tuple													=	shift_tokens_right(batch['''labels''']       ,       tokenizer.pad_token_id )
							assert batch["decoder_input_ids"][0, 0].item() == tokenizer.lang_code_to_id[tgt_lang]
							assert batch["decoder_input_ids"][0, -1].item() == tokenizer.eos_token_id
							assert batch["input_ids"][0, -2].item() == tokenizer.eos_token_id
							assert batch["input_ids"][0, -1].item() == tokenizer.lang_code_to_id[src_lang]

							break  # No need to test every batch




			@parameterized.expand([BART_TINY, BERT_BASE_CASED] )
			def  snake_case__     (   self							: Optional[int]       ,       a_							: Optional[Any] ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__ )
					__UpperCAmelCase    :     Any													=	make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() )
					__UpperCAmelCase    :     Any													=	max(len(tokenizer.encode(SCREAMING_SNAKE_CASE__ ) ) for a in ARTICLES )
					__UpperCAmelCase    :     int													=	max(len(tokenizer.encode(SCREAMING_SNAKE_CASE__ ) ) for a in SUMMARIES )
					__UpperCAmelCase    :     List[Any]													=	4
					__UpperCAmelCase    :     int													=	LegacySeqaSeqDataset(
					    SCREAMING_SNAKE_CASE__       ,       data_dir=SCREAMING_SNAKE_CASE__       ,       type_path='''train'''       ,       max_source_length=20       ,       max_target_length=SCREAMING_SNAKE_CASE__       ,       )
					__UpperCAmelCase    :     Any													=	DataLoader(SCREAMING_SNAKE_CASE__       ,       batch_size=2       ,       collate_fn=train_dataset.collate_fn )
					for batch in dataloader:
							assert batch["attention_mask"].shape == batch["input_ids"].shape
							# show that articles were trimmed.
							assert batch["input_ids"].shape[1] == max_len_source
							assert 20 >= batch["input_ids"].shape[1]  # trimmed significantly
							# show that targets were truncated
							assert batch["labels"].shape[1] == trunc_target  # Truncated
							assert max_len_target > trunc_target  # Truncated
							break  # No need to test every batch




			def  snake_case__     (   self							: int ):
					'''simple docstring'''





					__UpperCAmelCase    :     int													=	AutoTokenizer.from_pretrained('''facebook/mbart-large-cc25''' )

					__UpperCAmelCase    :     Tuple													=	Path(make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() ) )
					__UpperCAmelCase    :     Union[str, Any]													=	tmp_dir.joinpath('''train.source''' ).open().readlines()
					__UpperCAmelCase    :     int													=	Path(make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() ) )
					pack_data_dir(SCREAMING_SNAKE_CASE__       ,       SCREAMING_SNAKE_CASE__       ,       1_28       ,       SCREAMING_SNAKE_CASE__ )
					__UpperCAmelCase    :     List[str]													=	{x.name for x in tmp_dir.iterdir()}
					__UpperCAmelCase    :     Optional[Any]													=	{x.name for x in save_dir.iterdir()}
					__UpperCAmelCase    :     Optional[Any]													=	save_dir.joinpath('''train.source''' ).open().readlines()
					# orig: [' Sam ate lunch today.\n', 'Sams lunch ingredients.']
					# desired_packed: [' Sam ate lunch today.\n Sams lunch ingredients.']
					assert len(SCREAMING_SNAKE_CASE__ ) < len(SCREAMING_SNAKE_CASE__ )
					assert len(SCREAMING_SNAKE_CASE__ ) == 1
					assert len(packed_examples[0] ) == sum(len(SCREAMING_SNAKE_CASE__ ) for x in orig_examples )
					assert orig_paths == new_paths




			@pytest.mark.skipif(not FAIRSEQ_AVAILABLE       ,       reason='''This test requires fairseq''' )
			def  snake_case__     (   self							: str ):
					'''simple docstring'''





					if not FAIRSEQ_AVAILABLE:
							return
					__UpperCAmelCase    :     Optional[int]													=	self._get_dataset(max_len=64 )
					__UpperCAmelCase    :     Tuple													=	64
					__UpperCAmelCase    :     Any													=	ds.make_dynamic_sampler(SCREAMING_SNAKE_CASE__       ,       required_batch_size_multiple=SCREAMING_SNAKE_CASE__ )
					__UpperCAmelCase    :     List[Any]													=	[len(SCREAMING_SNAKE_CASE__ ) for x in batch_sampler]
					assert len(set(SCREAMING_SNAKE_CASE__ ) ) > 1  # it's not dynamic batch size if every batch is the same length
					assert sum(SCREAMING_SNAKE_CASE__ ) == len(SCREAMING_SNAKE_CASE__ )  # no dropped or added examples
					__UpperCAmelCase    :     Dict													=	DataLoader(SCREAMING_SNAKE_CASE__       ,       batch_sampler=SCREAMING_SNAKE_CASE__       ,       collate_fn=ds.collate_fn       ,       num_workers=2 )
					__UpperCAmelCase    :     Tuple													=	[]
					__UpperCAmelCase    :     Optional[int]													=	[]
					for batch in data_loader:
							__UpperCAmelCase    :     Any													=	batch['input_ids'].shape
							__UpperCAmelCase    :     Any													=	src_shape[0]
							assert bs % required_batch_size_multiple == 0 or bs < required_batch_size_multiple
							__UpperCAmelCase    :     List[Any]													=	np.product(batch['''input_ids'''].shape )
							num_src_per_batch.append(SCREAMING_SNAKE_CASE__ )
							if num_src_tokens > (max_tokens * 1.1):
									failures.append(SCREAMING_SNAKE_CASE__ )
					assert num_src_per_batch[0] == max(SCREAMING_SNAKE_CASE__ )
					if failures:
							raise AssertionError(F'too many tokens in {len(SCREAMING_SNAKE_CASE__ )} batches' )




			def  snake_case__     (   self							: Dict ):
					'''simple docstring'''





					__UpperCAmelCase    :     Union[str, Any]													=	self._get_dataset(max_len=5_12 )
					__UpperCAmelCase    :     Union[str, Any]													=	2
					__UpperCAmelCase    :     Tuple													=	ds.make_sortish_sampler(SCREAMING_SNAKE_CASE__       ,       shuffle=SCREAMING_SNAKE_CASE__ )

					__UpperCAmelCase    :     Tuple													=	DataLoader(SCREAMING_SNAKE_CASE__       ,       batch_size=SCREAMING_SNAKE_CASE__       ,       collate_fn=ds.collate_fn       ,       num_workers=2 )
					__UpperCAmelCase    :     Optional[Any]													=	DataLoader(SCREAMING_SNAKE_CASE__       ,       batch_size=SCREAMING_SNAKE_CASE__       ,       collate_fn=ds.collate_fn       ,       num_workers=2       ,       sampler=SCREAMING_SNAKE_CASE__ )

					__UpperCAmelCase    :     Optional[Any]													=	tokenizer.pad_token_id

					def count_pad_tokens(a_							: Dict       ,       a_							: Any="input_ids" ):
							return [batch[k].eq(SCREAMING_SNAKE_CASE__ ).sum().item() for batch in data_loader]

					assert sum(count_pad_tokens(SCREAMING_SNAKE_CASE__       ,       k='''labels''' ) ) < sum(count_pad_tokens(SCREAMING_SNAKE_CASE__       ,       k='''labels''' ) )
					assert sum(count_pad_tokens(SCREAMING_SNAKE_CASE__ ) ) < sum(count_pad_tokens(SCREAMING_SNAKE_CASE__ ) )
					assert len(SCREAMING_SNAKE_CASE__ ) == len(SCREAMING_SNAKE_CASE__ )




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: Any=10_00       ,       a_							: Any=1_28 ):
					'''simple docstring'''





					if os.getenv('''USE_REAL_DATA'''       ,       SCREAMING_SNAKE_CASE__ ):
							__UpperCAmelCase    :     Optional[Any]													=	'examples/seq2seq/wmt_en_ro'
							__UpperCAmelCase    :     Dict													=	max_len * 2 * 64
							if not Path(SCREAMING_SNAKE_CASE__ ).joinpath('''train.len''' ).exists():
									save_len_file(SCREAMING_SNAKE_CASE__       ,       SCREAMING_SNAKE_CASE__ )
					else:
							__UpperCAmelCase    :     Any													=	'examples/seq2seq/test_data/wmt_en_ro'
							__UpperCAmelCase    :     Tuple													=	max_len * 4
							save_len_file(SCREAMING_SNAKE_CASE__       ,       SCREAMING_SNAKE_CASE__ )

					__UpperCAmelCase    :     Any													=	AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__ )
					__UpperCAmelCase    :     Optional[Any]													=	SeqaSeqDataset(
					    SCREAMING_SNAKE_CASE__       ,       data_dir=SCREAMING_SNAKE_CASE__       ,       type_path='''train'''       ,       max_source_length=SCREAMING_SNAKE_CASE__       ,       max_target_length=SCREAMING_SNAKE_CASE__       ,       n_obs=SCREAMING_SNAKE_CASE__       ,       )
					return ds, max_tokens, tokenizer




			def  snake_case__     (   self							: Union[str, Any] ):
					'''simple docstring'''





					__UpperCAmelCase    :     Optional[int]													=	self._get_dataset()
					__UpperCAmelCase    :     Optional[Any]													=	set(DistributedSortishSampler(SCREAMING_SNAKE_CASE__       ,       2_56       ,       num_replicas=2       ,       rank=0       ,       add_extra_examples=SCREAMING_SNAKE_CASE__ ) )
					__UpperCAmelCase    :     List[Any]													=	set(DistributedSortishSampler(SCREAMING_SNAKE_CASE__       ,       2_56       ,       num_replicas=2       ,       rank=1       ,       add_extra_examples=SCREAMING_SNAKE_CASE__ ) )
					assert idsa.intersection(SCREAMING_SNAKE_CASE__ ) == set()




			@parameterized.expand(
			    [
			        MBART_TINY,
			        MARIAN_TINY,
			        T5_TINY,
			        BART_TINY,
			        PEGASUS_XSUM,
			    ]       ,       )
			def  snake_case__     (   self							: Tuple       ,       a_							: str ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__       ,       use_fast=SCREAMING_SNAKE_CASE__ )
					if tok_name == MBART_TINY:
							__UpperCAmelCase    :     Dict													=	SeqaSeqDataset(
							    SCREAMING_SNAKE_CASE__       ,       data_dir=make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() )       ,       type_path='''train'''       ,       max_source_length=4       ,       max_target_length=8       ,       src_lang='''EN'''       ,       tgt_lang='''FR'''       ,       )
							__UpperCAmelCase    :     Dict													=	train_dataset.dataset_kwargs
							assert "src_lang" in kwargs and "tgt_lang" in kwargs
					else:
							__UpperCAmelCase    :     Any													=	SeqaSeqDataset(
							    SCREAMING_SNAKE_CASE__       ,       data_dir=make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir() )       ,       type_path='''train'''       ,       max_source_length=4       ,       max_target_length=8       ,       )
							__UpperCAmelCase    :     List[Any]													=	train_dataset.dataset_kwargs
							assert "add_prefix_space" not in kwargs if tok_name != BART_TINY else "add_prefix_space" in kwargs
							assert len(SCREAMING_SNAKE_CASE__ ) == 1 if tok_name == BART_TINY else len(SCREAMING_SNAKE_CASE__ ) == 0









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()     )


