





import unicodedata
from dataclasses import dataclass
from typing import Optional, Union

import numpy as np

from transformers.data.data_collator import DataCollatorMixin
from transformers.file_utils import PaddingStrategy
from transformers.tokenization_utils_base import PreTrainedTokenizerBase





def 	a_    (							_lowercase	,						_lowercase	,						_lowercase	,						_lowercase       ):
						if isinstance(__lowerCAmelCase	,						__lowerCAmelCase       ):
												_UpperCamelCase      : Any         =   np.full((len(__lowerCAmelCase       ), sequence_length, 2)	,						__lowerCAmelCase       )
						else:
												_UpperCamelCase      : Optional[int]         =   np.full((len(__lowerCAmelCase       ), sequence_length)	,						__lowerCAmelCase       )

						for i, tensor in enumerate(__lowerCAmelCase       ):
												if padding_side == "right":
																		if isinstance(__lowerCAmelCase	,						__lowerCAmelCase       ):
																								_UpperCamelCase      : Tuple         =   tensor[:sequence_length]
																		else:
																								_UpperCamelCase      : Any         =   tensor[:sequence_length]
												else:
																		if isinstance(__lowerCAmelCase	,						__lowerCAmelCase       ):
																								_UpperCamelCase      : List[Any]         =   tensor[:sequence_length]
																		else:
																								_UpperCamelCase      : List[Any]         =   tensor[:sequence_length]

						return out_tensor.tolist()





def 	a_    (							_lowercase       ):
						_UpperCamelCase      : Any         =   ord(__lowerCAmelCase       )
						if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126):
												return True
						_UpperCamelCase      : List[Any]         =   unicodedata.category(__lowerCAmelCase       )
						if cat.startswith('''P'''       ):
												return True
						return False






@dataclass
class 			_a						(				UpperCamelCase_    ):
				UpperCamelCase								=   42
				UpperCamelCase								=   True
				UpperCamelCase								=   None
				UpperCamelCase								=   None
				UpperCamelCase								=   -100
				UpperCamelCase								=   "pt"






				def     snake_case     (			self		:   Tuple,			lowerCAmelCase__		:   Any							)     ->				int:




										'''simple docstring'''



										import torch

										_UpperCamelCase      : Tuple         =   """label""" if """label""" in features[0].keys() else """labels"""
										_UpperCamelCase      : int         =   [feature[label_name] for feature in features] if label_name in features[0].keys() else None
										_UpperCamelCase      : List[str]         =   self.tokenizer.pad(
										    _a,			padding=self.padding,			max_length=self.max_length,			pad_to_multiple_of=self.pad_to_multiple_of,			return_tensors='''pt''' if labels is None else None,			)

										if labels is None:
																return batch

										_UpperCamelCase      : List[Any]         =   torch.tensor(batch['''entity_ids''']							).shape[1]
										_UpperCamelCase      : Dict         =   self.tokenizer.padding_side
										if padding_side == "right":
																_UpperCamelCase      : Any         =   [
																    list(_a							) + [self.label_pad_token_id] * (sequence_length - len(_a							)) for label in labels
																]
										else:
																_UpperCamelCase      : List[str]         =   [
																    [self.label_pad_token_id] * (sequence_length - len(_a							)) + list(_a							) for label in labels
																]

										_UpperCamelCase      : List[str]         =   [feature["""ner_tags"""] for feature in features]
										_UpperCamelCase      : List[str]         =   padding_tensor(_a,			-1,			_a,			_a							)
										_UpperCamelCase      : Tuple         =   [feature["""original_entity_spans"""] for feature in features]
										_UpperCamelCase      : Tuple         =   padding_tensor(_a,			(-1, -1),			_a,			_a							)
										_UpperCamelCase      : Optional[Any]         =   {k: torch.tensor(_a,			dtype=torch.intaa							) for k, v in batch.items()}

										return batch










"""simple docstring"""




def 	a_    (							_lowercase	,						_lowercase       ):
						if discount_rate < 0:
												raise ValueError('''Discount rate cannot be negative'''       )
						if not cash_flows:
												raise ValueError('''Cash flows list cannot be empty'''       )
						_UpperCamelCase      : Optional[int]         =   sum(
						    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_lowercase       )       )
						return round(_lowercase	,						ndigits=2       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



