






import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
lowercase  :							Optional[int]			  =    sys.version_info >= (3, 10)

def      lowerCAmelCase__	(    _a       :			Optional[Any]=None  ,      _a       :			int=None    ):
		return field(default_factory=lambda: default  ,      metadata=_a    )




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   int
						A     :   float
						A     :   str
						A     :   bool




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   int						=					42
						A     :   str						=					field(default='toto'					,  metadata={'help': 'help message'}					)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   bool						=					False
						A     :   bool						=					True
						A     :   Optional[bool]						=					None




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   Optional[Any]						=					'titi'
						A     :   Union[str, Any]						=					'toto'




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   Optional[Any]						=					'titi'
						A     :   Any						=					'toto'
						A     :   Union[str, Any]						=					42




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   BasicEnum						=					"toto"






						def       _lowerCAmelCase       (	self				) ->				str:
								snake_case_				:							Optional[Any]						 =       BasicEnum(self.foo				)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   MixedTypeEnum						=					"toto"






						def       _lowerCAmelCase       (	self				) ->				Optional[Any]:
								snake_case_				:							List[str]						 =       MixedTypeEnum(self.foo				)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   Optional[int]						=					None
						A     :   Optional[float]						=					field(default=SCREAMING_SNAKE_CASE__					,  metadata={'help': 'help message'}					)
						A     :   Optional[str]						=					None
						A     :   Optional[List[str]]						=					list_field(default=[]					)
						A     :   Optional[List[int]]						=					list_field(default=[]					)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   List[int]						=					list_field(default=[]					)
						A     :   List[int]						=					list_field(default=[1, 2, 3]					)
						A     :   List[str]						=					list_field(default=['Hallo', 'Bonjour', 'Hello']					)
						A     :   List[float]						=					list_field(default=[0.1, 0.2, 0.3]					)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   List[int]						=					field()
						A     :   str						=					field()
						A     :   BasicEnum						=					field()






						def       _lowerCAmelCase       (	self				) ->				Tuple:
								snake_case_				:							Tuple						 =       BasicEnum(self.required_enum				)




@dataclass
class 		UpperCAmelCase_						:


						'''simple docstring'''




						A     :   int
						A     :   "BasicEnum"						=					field()
						A     :   "Optional[bool]"						=					None
						A     :   "str"						=					field(default='toto'					,  metadata={'help': 'help message'}					)
						A     :   "List[str]"						=					list_field(default=['Hallo', 'Bonjour', 'Hello']					)


if is_python_no_less_than_3_10:




							@dataclass
							class 		UpperCAmelCase_						:


													'''simple docstring'''




													A     :   bool						=					False
													A     :   bool						=					True
													A     :   bool | None						=					None




							@dataclass
							class 		UpperCAmelCase_						:


													'''simple docstring'''




													A     :   int | None						=					None
													A     :   float | None						=					field(default=SCREAMING_SNAKE_CASE__					,  metadata={'help': 'help message'}					)
													A     :   str | None						=					None
													A     :   list[str] | None						=					list_field(default=[]					)
													A     :   list[int] | None						=					list_field(default=[]					)




class 		UpperCAmelCase_						(	unittest.TestCase					):


						'''simple docstring'''




						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Any:
								self.assertEqual(len(a._actions				)		,				len(b._actions				)				)
								for x, y in zip(a._actions		,				b._actions				):
										snake_case_				:							Dict						 =       {k: v for k, v in vars(_SCREAMING_SNAKE_CASE				).items() if k != "container"}
										snake_case_				:							Dict						 =       {k: v for k, v in vars(_SCREAMING_SNAKE_CASE				).items() if k != "container"}

										# Choices with mixed type have custom function as "type"
										# So we need to compare results directly for equality
										if xx.get("choices"		,				_SCREAMING_SNAKE_CASE				) and yy.get("choices"		,				_SCREAMING_SNAKE_CASE				):
												for expected_choice in yy["choices"] + xx["choices"]:
														self.assertEqual(xx["type"](_SCREAMING_SNAKE_CASE				)		,				yy["type"](_SCREAMING_SNAKE_CASE				)				)
												del xx["type"], yy["type"]

										self.assertEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							List[Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       argparse.ArgumentParser()
								expected.add_argument("--foo"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--bar"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--baz"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--flag"		,				type=_SCREAMING_SNAKE_CASE		,				default=_SCREAMING_SNAKE_CASE		,				const=_SCREAMING_SNAKE_CASE		,				nargs="?"				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       ["--foo", "1", "--baz", "quux", "--bar", "0.5"]
								((snake_case_) ,       )				:							int						 =       parser.parse_args_into_dataclasses(_SCREAMING_SNAKE_CASE		,				look_for_args_file=_SCREAMING_SNAKE_CASE				)
								self.assertFalse(example.flag				)






						def       _lowerCAmelCase       (	self				) ->				str:
								snake_case_				:							int						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Dict						 =       argparse.ArgumentParser()
								expected.add_argument("--foo"		,				default=42		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--baz"		,				default="toto"		,				type=_SCREAMING_SNAKE_CASE		,				help="help message"				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							Tuple						 =       argparse.ArgumentParser()
								expected.add_argument("--foo"		,				type=_SCREAMING_SNAKE_CASE		,				default=_SCREAMING_SNAKE_CASE		,				const=_SCREAMING_SNAKE_CASE		,				nargs="?"				)
								expected.add_argument("--baz"		,				type=_SCREAMING_SNAKE_CASE		,				default=_SCREAMING_SNAKE_CASE		,				const=_SCREAMING_SNAKE_CASE		,				nargs="?"				)
								# A boolean no_* argument always has to come after its "default: True" regular counter-part
								# and its default must be set to False
								expected.add_argument("--no_baz"		,				action="store_false"		,				default=_SCREAMING_SNAKE_CASE		,				dest="baz"				)
								expected.add_argument("--opt"		,				type=_SCREAMING_SNAKE_CASE		,				default=_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       [WithDefaultBoolExample]
								if is_python_no_less_than_3_10:
										dataclass_types.append(_SCREAMING_SNAKE_CASE				)

								for dataclass_type in dataclass_types:
										snake_case_				:							Union[str, Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)
										self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Optional[int]						 =       parser.parse_args([]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				opt=_SCREAMING_SNAKE_CASE				)				)

										snake_case_				:							Tuple						 =       parser.parse_args(["--foo", "--no_baz"]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				opt=_SCREAMING_SNAKE_CASE				)				)

										snake_case_				:							Optional[Any]						 =       parser.parse_args(["--foo", "--baz"]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				opt=_SCREAMING_SNAKE_CASE				)				)

										snake_case_				:							int						 =       parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				opt=_SCREAMING_SNAKE_CASE				)				)

										snake_case_				:							List[Any]						 =       parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				opt=_SCREAMING_SNAKE_CASE				)				)






						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							Tuple						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       argparse.ArgumentParser()
								expected.add_argument(
								    "--foo"		,				default="toto"		,				choices=["titi", "toto", 42]		,				type=make_choice_type_function(["titi", "toto", 42]				)		,				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Tuple						 =       parser.parse_args([]				)
								self.assertEqual(args.foo		,				"toto"				)
								snake_case_				:							int						 =       parser.parse_args_into_dataclasses([]				)[0]
								self.assertEqual(enum_ex.foo		,				MixedTypeEnum.toto				)

								snake_case_				:							Optional[int]						 =       parser.parse_args(["--foo", "titi"]				)
								self.assertEqual(args.foo		,				"titi"				)
								snake_case_				:							str						 =       parser.parse_args_into_dataclasses(["--foo", "titi"]				)[0]
								self.assertEqual(enum_ex.foo		,				MixedTypeEnum.titi				)

								snake_case_				:							Any						 =       parser.parse_args(["--foo", "42"]				)
								self.assertEqual(args.foo		,				42				)
								snake_case_				:							str						 =       parser.parse_args_into_dataclasses(["--foo", "42"]				)[0]
								self.assertEqual(enum_ex.foo		,				MixedTypeEnum.fourtytwo				)






						def       _lowerCAmelCase       (	self				) ->				int:




								@dataclass
								class 		UpperCAmelCase_						:


														'''simple docstring'''




														A     :   Literal["titi", "toto", 42]						=					"toto"




								snake_case_				:							Union[str, Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							str						 =       argparse.ArgumentParser()
								expected.add_argument(
								    "--foo"		,				default="toto"		,				choices=("titi", "toto", 42)		,				type=make_choice_type_function(["titi", "toto", 42]				)		,				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							List[str]						 =       parser.parse_args([]				)
								self.assertEqual(args.foo		,				"toto"				)

								snake_case_				:							Optional[int]						 =       parser.parse_args(["--foo", "titi"]				)
								self.assertEqual(args.foo		,				"titi"				)

								snake_case_				:							str						 =       parser.parse_args(["--foo", "42"]				)
								self.assertEqual(args.foo		,				42				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							int						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Tuple						 =       argparse.ArgumentParser()
								expected.add_argument("--foo_int"		,				nargs="+"		,				default=[]		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--bar_int"		,				nargs="+"		,				default=[1, 2, 3]		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--foo_str"		,				nargs="+"		,				default=["Hallo", "Bonjour", "Hello"]		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--foo_float"		,				nargs="+"		,				default=[0.1, 0.2, 0.3]		,				type=_SCREAMING_SNAKE_CASE				)

								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[Any]						 =       parser.parse_args([]				)
								self.assertEqual(
								    _SCREAMING_SNAKE_CASE		,				Namespace(foo_int=[]		,				bar_int=[1, 2, 3]		,				foo_str=["Hallo", "Bonjour", "Hello"]		,				foo_float=[0.1, 0.2, 0.3]				)		,				)

								snake_case_				:							Any						 =       parser.parse_args("--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7".split()				)
								self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo_int=[1]		,				bar_int=[2, 3]		,				foo_str=["a", "b", "c"]		,				foo_float=[0.1, 0.7]				)				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							Optional[int]						 =       argparse.ArgumentParser()
								expected.add_argument("--foo"		,				default=_SCREAMING_SNAKE_CASE		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--bar"		,				default=_SCREAMING_SNAKE_CASE		,				type=_SCREAMING_SNAKE_CASE		,				help="help message"				)
								expected.add_argument("--baz"		,				default=_SCREAMING_SNAKE_CASE		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--ces"		,				nargs="+"		,				default=[]		,				type=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--des"		,				nargs="+"		,				default=[]		,				type=_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       [OptionalExample]
								if is_python_no_less_than_3_10:
										dataclass_types.append(_SCREAMING_SNAKE_CASE				)

								for dataclass_type in dataclass_types:
										snake_case_				:							Dict						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

										self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							List[str]						 =       parser.parse_args([]				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=_SCREAMING_SNAKE_CASE		,				bar=_SCREAMING_SNAKE_CASE		,				baz=_SCREAMING_SNAKE_CASE		,				ces=[]		,				des=[]				)				)

										snake_case_				:							Optional[int]						 =       parser.parse_args("--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3".split()				)
										self.assertEqual(_SCREAMING_SNAKE_CASE		,				Namespace(foo=12		,				bar=3.14		,				baz="42"		,				ces=["a", "b", "c"]		,				des=[1, 2, 3]				)				)






						def       _lowerCAmelCase       (	self				) ->				str:
								snake_case_				:							List[str]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       argparse.ArgumentParser()
								expected.add_argument("--required_list"		,				nargs="+"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--required_str"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument(
								    "--required_enum"		,				type=make_choice_type_function(["titi", "toto"]				)		,				choices=["titi", "toto"]		,				required=_SCREAMING_SNAKE_CASE		,				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				List[str]:
								snake_case_				:							Optional[int]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Dict						 =       argparse.ArgumentParser()
								expected.add_argument("--foo"		,				type=_SCREAMING_SNAKE_CASE		,				required=_SCREAMING_SNAKE_CASE				)
								expected.add_argument(
								    "--required_enum"		,				type=make_choice_type_function(["titi", "toto"]				)		,				choices=["titi", "toto"]		,				required=_SCREAMING_SNAKE_CASE		,				)
								expected.add_argument("--opt"		,				type=_SCREAMING_SNAKE_CASE		,				default=_SCREAMING_SNAKE_CASE				)
								expected.add_argument("--baz"		,				default="toto"		,				type=_SCREAMING_SNAKE_CASE		,				help="help message"				)
								expected.add_argument("--foo_str"		,				nargs="+"		,				default=["Hallo", "Bonjour", "Hello"]		,				type=_SCREAMING_SNAKE_CASE				)
								self.argparsersEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				int:
								snake_case_				:							List[str]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							List[str]						 =       {
								    "foo": 12,
								    "bar": 3.14,
								    "baz": "42",
								    "flag": True,
								}

								snake_case_				:							Any						 =       parser.parse_dict(_SCREAMING_SNAKE_CASE				)[0]
								snake_case_				:							Union[str, Any]						 =       BasicExample(**_SCREAMING_SNAKE_CASE				)
								self.assertEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								snake_case_				:							List[Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       {
								    "foo": 12,
								    "bar": 3.14,
								    "baz": "42",
								    "flag": True,
								    "extra": 42,
								}

								self.assertRaises(_SCREAMING_SNAKE_CASE		,				parser.parse_dict		,				_SCREAMING_SNAKE_CASE		,				allow_extra_keys=_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								snake_case_				:							List[Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       {
								    "foo": 12,
								    "bar": 3.14,
								    "baz": "42",
								    "flag": True,
								}
								with tempfile.TemporaryDirectory() as tmp_dir:
										snake_case_				:							int						 =       os.path.join(_SCREAMING_SNAKE_CASE		,				"temp_json"				)
										os.mkdir(_SCREAMING_SNAKE_CASE				)
										with open(temp_local_path + ".json"		,				"w+"				) as f:
												json.dump(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       parser.parse_yaml_file(Path(temp_local_path + ".json"				)				)[0]

								snake_case_				:							Optional[Any]						 =       BasicExample(**_SCREAMING_SNAKE_CASE				)
								self.assertEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							Any						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							List[str]						 =       {
								    "foo": 12,
								    "bar": 3.14,
								    "baz": "42",
								    "flag": True,
								}
								with tempfile.TemporaryDirectory() as tmp_dir:
										snake_case_				:							Optional[Any]						 =       os.path.join(_SCREAMING_SNAKE_CASE		,				"temp_yaml"				)
										os.mkdir(_SCREAMING_SNAKE_CASE				)
										with open(temp_local_path + ".yaml"		,				"w+"				) as f:
												yaml.dump(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Dict						 =       parser.parse_yaml_file(Path(temp_local_path + ".yaml"				)				)[0]
								snake_case_				:							Optional[int]						 =       BasicExample(**_SCREAMING_SNAKE_CASE				)
								self.assertEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				str:
								snake_case_				:							Union[str, Any]						 =       HfArgumentParser(_SCREAMING_SNAKE_CASE				)
								self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)








from typing import List, Union

import numpy as np

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, logging
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, ChunkPipeline


lowercase  :							Dict			  =    logging.get_logger(__name__)




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				List[Any]:
								if isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       [label.strip() for label in labels.split(","				) if label.strip()]
								return labels






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								if len(_SCREAMING_SNAKE_CASE				) == 0 or len(_SCREAMING_SNAKE_CASE				) == 0:
										raise ValueError("You must include at least one label and at least one sequence."				)
								if hypothesis_template.format(labels[0]				) == hypothesis_template:
										raise ValueError(
										    (
										        "The provided hypothesis_template \"{}\" was not able to be formatted with the target labels. "
										        "Make sure the passed template includes formatting syntax such as {{}} where the label should go."
										    ).format(_SCREAMING_SNAKE_CASE				)				)

								if isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       [sequences]

								snake_case_				:							List[str]						 =       []
								for sequence in sequences:
										sequence_pairs.extend([[sequence, hypothesis_template.format(_SCREAMING_SNAKE_CASE				)] for label in labels]				)

								return sequence_pairs, sequences




@add_end_docstrings(SCREAMING_SNAKE_CASE__					)
class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE=ZeroShotClassificationArgumentHandler()		,				*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								snake_case_				:							Dict						 =       args_parser
								super().__init__(*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)
								if self.entailment_id == -1:
										logger.warning(
										    "Failed to determine 'entailment' label id from the label2id mapping in the model config. Setting to "
										    "-1. Define a descriptive label2id mapping in the model config to ensure correct outputs."				)






						@property
						def       _lowerCAmelCase       (	self				) ->				str:
								for label, ind in self.model.config.labelaid.items():
										if label.lower().startswith("entail"				):
												return ind
								return -1






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=TruncationStrategy.ONLY_FIRST		,				**_SCREAMING_SNAKE_CASE				) ->				Dict:
								snake_case_				:							List[Any]						 =       self.framework
								if self.tokenizer.pad_token is None:
										# Override for tokenizers not supporting padding
										logger.error(
										    "Tokenizer was not supporting padding necessary for zero-shot, attempting to use "
										    " `pad_token=eos_token`"				)
										snake_case_				:							List[str]						 =       self.tokenizer.eos_token
								try:
										snake_case_				:							Union[str, Any]						 =       self.tokenizer(
										    _SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE		,				return_tensors=_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				truncation=_SCREAMING_SNAKE_CASE		,				)
								except Exception as e:
										if "too short" in str(_SCREAMING_SNAKE_CASE				):
												# tokenizers might yell that we want to truncate
												# to a value that is not even reached by the input.
												# In that case we don't want to truncate.
												# It seems there's not a really better way to catch that
												# exception.

												snake_case_				:							Union[str, Any]						 =       self.tokenizer(
												    _SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE		,				return_tensors=_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				truncation=TruncationStrategy.DO_NOT_TRUNCATE		,				)
										else:
												raise e

								return inputs






						def       _lowerCAmelCase       (	self		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[int]:
								if kwargs.get("multi_class"		,				_SCREAMING_SNAKE_CASE				) is not None:
										snake_case_				:							Any						 =       kwargs["multi_class"]
										logger.warning(
										    "The `multi_class` argument has been deprecated and renamed to `multi_label`. "
										    "`multi_class` will be removed in a future version of Transformers."				)
								snake_case_				:							Any						 =       {}
								if "candidate_labels" in kwargs:
										snake_case_				:							Tuple						 =       self._args_parser._parse_labels(kwargs["candidate_labels"]				)
								if "hypothesis_template" in kwargs:
										snake_case_				:							Optional[Any]						 =       kwargs["hypothesis_template"]

								snake_case_				:							Dict						 =       {}
								if "multi_label" in kwargs:
										snake_case_				:							List[Any]						 =       kwargs["multi_label"]
								return preprocess_params, {}, postprocess_params






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE		,				) ->				str:
								if len(_SCREAMING_SNAKE_CASE				) == 0:
										pass
								elif len(_SCREAMING_SNAKE_CASE				) == 1 and "candidate_labels" not in kwargs:
										snake_case_				:							int						 =       args[0]
								else:
										raise ValueError(f'''Unable to understand extra arguments {args}'''				)

								return super().__call__(_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE="This example is {}."				) ->				str:
								snake_case_ ,       snake_case_				:							Optional[int]						 =       self._args_parser(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								for i, (candidate_label, sequence_pair) in enumerate(zip(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)				):
										snake_case_				:							str						 =       self._parse_and_tokenize([sequence_pair]				)

										yield {
										    "candidate_label": candidate_label,
										    "sequence": sequences[0],
										    "is_last": i == len(_SCREAMING_SNAKE_CASE				) - 1,
										    **model_input,
										}






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				Any:
								snake_case_				:							Optional[Any]						 =       inputs["candidate_label"]
								snake_case_				:							Dict						 =       inputs["sequence"]
								snake_case_				:							Optional[int]						 =       {k: inputs[k] for k in self.tokenizer.model_input_names}
								snake_case_				:							Dict						 =       self.model(**_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       {
								    "candidate_label": candidate_label,
								    "sequence": sequence,
								    "is_last": inputs["is_last"],
								    **outputs,
								}
								return model_outputs






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=False				) ->				Any:
								snake_case_				:							str						 =       [outputs["candidate_label"] for outputs in model_outputs]
								snake_case_				:							Union[str, Any]						 =       [outputs["sequence"] for outputs in model_outputs]
								snake_case_				:							List[Any]						 =       np.concatenate([output["logits"].numpy() for output in model_outputs]				)
								snake_case_				:							Tuple						 =       logits.shape[0]
								snake_case_				:							List[Any]						 =       len(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							int						 =       N // n
								snake_case_				:							Optional[Any]						 =       logits.reshape((num_sequences, n, -1)				)

								if multi_label or len(_SCREAMING_SNAKE_CASE				) == 1:
										# softmax over the entailment vs. contradiction dim for each label independently
										snake_case_				:							Any						 =       self.entailment_id
										snake_case_				:							List[str]						 =       -1 if entailment_id == 0 else 0
										snake_case_				:							Dict						 =       reshaped_outputs[..., [contradiction_id, entailment_id]]
										snake_case_				:							List[str]						 =       np.exp(_SCREAMING_SNAKE_CASE				) / np.exp(_SCREAMING_SNAKE_CASE				).sum(-1		,				keepdims=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       scores[..., 1]
								else:
										# softmax the "entailment" logits over all candidate labels
										snake_case_				:							List[str]						 =       reshaped_outputs[..., self.entailment_id]
										snake_case_				:							Optional[Any]						 =       np.exp(_SCREAMING_SNAKE_CASE				) / np.exp(_SCREAMING_SNAKE_CASE				).sum(-1		,				keepdims=_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       list(reversed(scores[0].argsort()				)				)
								return {
								    "sequence": sequences[0],
								    "labels": [candidate_labels[i] for i in top_inds],
								    "scores": scores[0, top_inds].tolist(),
								}
