'''simple docstring'''





import enum
import warnings

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, is_tf_available, is_torch_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
			import tensorflow as tf

			from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

if is_torch_available():
			from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

lowerCAmelCase_	:		Optional[int]			=     logging.get_logger(__name__)




class 		SCREAMING_SNAKE_CASE     (					enum.Enum	):







				'''simple docstring'''
				UpperCAmelCase__							=							0
				UpperCAmelCase__							=							1





@add_end_docstrings(SCREAMING_SNAKE_CASE	)
class 		SCREAMING_SNAKE_CASE     (					SCREAMING_SNAKE_CASE	):







				'''simple docstring'''
				UpperCAmelCase__							=							'''generated'''





				def __init__(						self					:						Any       ,		*lowercase__					:						str       ,		**lowercase__					:						Union[str, Any]					)							->Optional[Any]:


										'''simple docstring'''




										super().__init__(*lowercase__       ,		**lowercase__					)

										self.check_model_type(
										    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
										    if self.framework == "tf"
										    else MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING					)





				def  snake_case__				(						self					:						int       ,		lowercase__					:						Optional[Any]=None       ,		lowercase__					:						Optional[Any]=None       ,		lowercase__					:						Optional[Any]=None       ,		lowercase__					:						Tuple=None       ,		lowercase__					:						Union[str, Any]=None       ,		lowercase__					:						Dict=None       ,		**lowercase__					:						List[str]       ,		)							->Optional[int]:


										'''simple docstring'''




										_UpperCamelCase			:			List[str]   			=						{}
										if truncation is not None:
																_UpperCamelCase			:			str   			=						truncation

										_UpperCamelCase			:			int   			=						generate_kwargs

										_UpperCamelCase			:			Optional[Any]   			=						{}
										if return_tensors is not None and return_type is None:
																_UpperCamelCase			:			Tuple   			=						ReturnType.TENSORS if return_tensors else ReturnType.TEXT
										if return_type is not None:
																_UpperCamelCase			:			List[Any]   			=						return_type

										if clean_up_tokenization_spaces is not None:
																_UpperCamelCase			:			Dict   			=						clean_up_tokenization_spaces

										if stop_sequence is not None:
																_UpperCamelCase			:			Optional[int]   			=						self.tokenizer.encode(lowercase__       ,		add_special_tokens=lowercase__					)
																if len(lowercase__					) > 1:
																						warnings.warn(
																						    "Stopping on a multiple token sequence is not yet supported on transformers. The first token of"
																						    " the stop sequence will be used as the stop sequence string in the interim."					)
																_UpperCamelCase			:			List[Any]   			=						stop_sequence_ids[0]

										return preprocess_params, forward_params, postprocess_params





				def  snake_case__				(						self					:						str       ,		lowercase__					:						int       ,		lowercase__					:						int       ,		lowercase__					:						int					)							->str:


										'''simple docstring'''




										return True





				def  snake_case__				(						self					:						Tuple       ,		*lowercase__					:						Union[str, Any]       ,		lowercase__					:						int					)							->Tuple:


										'''simple docstring'''




										_UpperCamelCase			:			Any   			=						self.model.config.prefix if self.model.config.prefix is not None else ""
										if isinstance(args[0]       ,		lowercase__					):
																if self.tokenizer.pad_token_id is None:
																						raise ValueError("Please make sure that the tokenizer has a pad_token_id when using a batch input"					)
																_UpperCamelCase			:			Tuple   			=						([prefix + arg for arg in args[0]],)
																_UpperCamelCase			:			Any   			=						True

										elif isinstance(args[0]       ,		lowercase__					):
																_UpperCamelCase			:			Optional[Any]   			=						(prefix + args[0],)
																_UpperCamelCase			:			Union[str, Any]   			=						False
										else:
																raise ValueError(
																    f''' `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`'''					)
										_UpperCamelCase			:			Tuple   			=						self.tokenizer(*lowercase__       ,		padding=lowercase__       ,		truncation=lowercase__       ,		return_tensors=self.framework					)
										# This is produced by tokenizers but is an invalid generate kwargs
										if "token_type_ids" in inputs:
																del inputs["token_type_ids"]
										return inputs





				def __call__(						self					:						List[str]       ,		*lowercase__					:						str       ,		**lowercase__					:						Union[str, Any]					)							->Any:


										'''simple docstring'''




										_UpperCamelCase			:			Optional[Any]   			=						super().__call__(*lowercase__       ,		**lowercase__					)
										if (
										    isinstance(args[0]       ,		lowercase__					)
										    and all(isinstance(lowercase__       ,		lowercase__					) for el in args[0]					)
										    and all(len(lowercase__					) == 1 for res in result					)
										):
																return [res[0] for res in result]
										return result





				def  snake_case__				(						self					:						Optional[int]       ,		lowercase__					:						str       ,		lowercase__					:						Optional[Any]=TruncationStrategy.DO_NOT_TRUNCATE       ,		**lowercase__					:						Dict					)							->Optional[int]:


										'''simple docstring'''




										_UpperCamelCase			:			Optional[Any]   			=						self._parse_and_tokenize(lowercase__       ,		truncation=lowercase__       ,		**lowercase__					)
										return inputs





				def  snake_case__				(						self					:						Union[str, Any]       ,		lowercase__					:						int       ,		**lowercase__					:						Optional[Any]					)							->int:


										'''simple docstring'''




										if self.framework == "pt":
																_UpperCamelCase			,       _UpperCamelCase			:			List[Any]   			=						model_inputs["input_ids"].shape
										elif self.framework == "tf":
																_UpperCamelCase			,       _UpperCamelCase			:			int   			=						tf.shape(model_inputs["input_ids"]					).numpy()

										_UpperCamelCase			:			Optional[Any]   			=						generate_kwargs.get("min_length"       ,		self.model.config.min_length					)
										_UpperCamelCase			:			Union[str, Any]   			=						generate_kwargs.get("max_length"       ,		self.model.config.max_length					)
										self.check_inputs(lowercase__       ,		generate_kwargs["min_length"]       ,		generate_kwargs["max_length"]					)
										_UpperCamelCase			:			Optional[int]   			=						self.model.generate(**lowercase__       ,		**lowercase__					)
										_UpperCamelCase			:			int   			=						output_ids.shape[0]
										if self.framework == "pt":
																_UpperCamelCase			:			Optional[Any]   			=						output_ids.reshape(lowercase__       ,		out_b // in_b       ,		*output_ids.shape[1:]					)
										elif self.framework == "tf":
																_UpperCamelCase			:			int   			=						tf.reshape(lowercase__       ,		(in_b, out_b // in_b, *output_ids.shape[1:])					)
										return {"output_ids": output_ids}







				def  snake_case__				(						self					:						List[str]       ,		lowercase__					:						str       ,		lowercase__					:						Optional[Any]=ReturnType.TEXT       ,		lowercase__					:						Dict=False					)							->Dict:


										'''simple docstring'''




										_UpperCamelCase			:			Dict   			=						[]
										for output_ids in model_outputs["output_ids"][0]:
																if return_type == ReturnType.TENSORS:
																						_UpperCamelCase			:			Optional[int]   			=						{f'''{self.return_name}_token_ids''': output_ids}
																elif return_type == ReturnType.TEXT:
																						_UpperCamelCase			:			int   			=						{
																						    f'''{self.return_name}_text''': self.tokenizer.decode(
																						        lowercase__       ,		skip_special_tokens=lowercase__       ,		clean_up_tokenization_spaces=lowercase__       ,		)
																						}
																records.append(lowercase__					)
										return records





@add_end_docstrings(SCREAMING_SNAKE_CASE	)
class 		SCREAMING_SNAKE_CASE     (					SCREAMING_SNAKE_CASE	):







				'''simple docstring'''
				UpperCAmelCase__							=							'''summary'''





				def __call__(						self					:						Optional[int]       ,		*lowercase__					:						Any       ,		**lowercase__					:						List[str]					)							->Optional[Any]:


										'''simple docstring'''




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







				def  snake_case__				(						self					:						Dict       ,		lowercase__					:						int       ,		lowercase__					:						int       ,		lowercase__					:						int					)							->bool:


										'''simple docstring'''




										if max_length < min_length:
																logger.warning(f'''Your min_length={min_length} must be inferior than your max_length={max_length}.'''					)

										if input_length < max_length:
																logger.warning(
																    f'''Your max_length is set to {max_length}, but your input_length is only {input_length}. Since this is '''
																    "a summarization task, where outputs shorter than the input are typically wanted, you might "
																    f'''consider decreasing max_length manually, e.g. summarizer(\'...\', max_length={input_length//2})'''					)





@add_end_docstrings(SCREAMING_SNAKE_CASE	)
class 		SCREAMING_SNAKE_CASE     (					SCREAMING_SNAKE_CASE	):







				'''simple docstring'''
				UpperCAmelCase__							=							'''translation'''





				def  snake_case__				(						self					:						List[str]       ,		lowercase__					:						int       ,		lowercase__					:						int       ,		lowercase__					:						int					)							->Tuple:


										'''simple docstring'''




										if input_length > 0.9 * max_length:
																logger.warning(
																    f'''Your input_length: {input_length} is bigger than 0.9 * max_length: {max_length}. You might consider '''
																    "increasing your max_length manually, e.g. translator('...', max_length=400)"					)
										return True





				def  snake_case__				(						self					:						int       ,		*lowercase__					:						Union[str, Any]       ,		lowercase__					:						Optional[int]=TruncationStrategy.DO_NOT_TRUNCATE       ,		lowercase__					:						Tuple=None       ,		lowercase__					:						List[str]=None					)							->Optional[int]:


										'''simple docstring'''




										if getattr(self.tokenizer       ,		"_build_translation_inputs"       ,		lowercase__					):
																return self.tokenizer._build_translation_inputs(
																    *lowercase__       ,		return_tensors=self.framework       ,		truncation=lowercase__       ,		src_lang=lowercase__       ,		tgt_lang=lowercase__					)
										else:
																return super()._parse_and_tokenize(*lowercase__       ,		truncation=lowercase__					)





				def  snake_case__				(						self					:						Union[str, Any]       ,		lowercase__					:						Optional[Any]=None       ,		lowercase__					:						List[Any]=None       ,		**lowercase__					:						Optional[int]					)							->Union[str, Any]:


										'''simple docstring'''




										_UpperCamelCase			,       _UpperCamelCase			,       _UpperCamelCase			:			Dict   			=						super()._sanitize_parameters(**lowercase__					)
										if src_lang is not None:
																_UpperCamelCase			:			Union[str, Any]   			=						src_lang
										if tgt_lang is not None:
																_UpperCamelCase			:			str   			=						tgt_lang
										if src_lang is None and tgt_lang is None:
																# Backward compatibility, direct arguments use is preferred.
																_UpperCamelCase			:			Optional[Any]   			=						kwargs.get("task"       ,		self.task					)
																_UpperCamelCase			:			int   			=						task.split("_"					)
																if task and len(lowercase__					) == 4:
																						# translation, XX, to YY
																						_UpperCamelCase			:			str   			=						items[1]
																						_UpperCamelCase			:			List[Any]   			=						items[3]
										return preprocess_params, forward_params, postprocess_params







				def __call__(						self					:						List[Any]       ,		*lowercase__					:						Dict       ,		**lowercase__					:						Optional[int]					)							->Tuple:


										'''simple docstring'''




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



'''simple docstring'''





lowerCAmelCase_	:		Union[str, Any]			=     """
# Transformers 설치 방법
! pip install transformers datasets
# 마지막 릴리스 대신 소스에서 설치하려면, 위 명령을 주석으로 바꾸고 아래 명령을 해제하세요.
# ! pip install git+https://github.com/huggingface/transformers.git
"""

lowerCAmelCase_	:		List[Any]			=     [{"""type""": """code""", """content""": INSTALL_CONTENT}]
lowerCAmelCase_	:		int			=     {
    """{processor_class}""": """FakeProcessorClass""",
    """{model_class}""": """FakeModelClass""",
    """{object_class}""": """FakeObjectClass""",
}


