

from sklearn.metrics import recall_score

import datasets


SCREAMING_SNAKE_CASE_        =      '\nRecall is the fraction of the positive examples that were correctly labeled by the model as positive. It can be computed with the equation:\nRecall = TP / (TP + FN)\nWhere TP is the true positives and FN is the false negatives.\n'


SCREAMING_SNAKE_CASE_        =      '\nArgs:\n- **predictions** (`list` of `int`): The predicted labels.\n- **references** (`list` of `int`): The ground truth labels.\n- **labels** (`list` of `int`): The set of labels to include when `average` is not set to `binary`, and their order when average is `None`. Labels present in the data can be excluded in this input, for example to calculate a multiclass average ignoring a majority negative class, while labels not present in the data will result in 0 components in a macro average. For multilabel targets, labels are column indices. By default, all labels in y_true and y_pred are used in sorted order. Defaults to None.\n- **pos_label** (`int`): The class label to use as the \'positive class\' when calculating the recall. Defaults to `1`.\n- **average** (`string`): This parameter is required for multiclass/multilabel targets. If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data. Defaults to `\'binary\'`.\n    - `\'binary\'`: Only report results for the class specified by `pos_label`. This is applicable only if the target labels and predictions are binary.\n    - `\'micro\'`: Calculate metrics globally by counting the total true positives, false negatives, and false positives.\n    - `\'macro\'`: Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.\n    - `\'weighted\'`: Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters `\'macro\'` to account for label imbalance. Note that it can result in an F-score that is not between precision and recall.\n    - `\'samples\'`: Calculate metrics for each instance, and find their average (only meaningful for multilabel classification).\n- **sample_weight** (`list` of `float`): Sample weights Defaults to `None`.\n- **zero_division** (): Sets the value to return when there is a zero division. Defaults to .\n    - `\'warn\'`: If there is a zero division, the return value is `0`, but warnings are also raised.\n    - `0`: If there is a zero division, the return value is `0`.\n    - `1`: If there is a zero division, the return value is `1`.\n\nReturns:\n- **recall** (`float`, or `array` of `float`): Either the general recall score, or the recall scores for individual classes, depending on the values input to `labels` and `average`. Minimum possible value is 0. Maximum possible value is 1. A higher recall means that more of the positive examples have been labeled correctly. Therefore, a higher recall is generally considered better.\n\nExamples:\n\n    Example 1-A simple example with some errors\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1])\n        >>> print(results)\n        {\'recall\': 0.6666666666666666}\n\n    Example 2-The same example as Example 1, but with `pos_label=0` instead of the default `pos_label=1`.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], pos_label=0)\n        >>> print(results)\n        {\'recall\': 0.5}\n\n    Example 3-The same example as Example 1, but with `sample_weight` included.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> sample_weight = [0.9, 0.2, 0.9, 0.3, 0.8]\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], sample_weight=sample_weight)\n        >>> print(results)\n        {\'recall\': 0.55}\n\n    Example 4-A multiclass example, using different averages.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> predictions = [0, 2, 1, 0, 0, 1]\n        >>> references = [0, 1, 2, 0, 1, 2]\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'macro\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'micro\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'weighted\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=None)\n        >>> print(results)\n        {\'recall\': array([1., 0., 0.])}\n'


SCREAMING_SNAKE_CASE_        =      '\n@article{scikit-learn, title={Scikit-learn: Machine Learning in {P}ython}, author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V. and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P. and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.}, journal={Journal of Machine Learning Research}, volume={12}, pages={2825--2830}, year={2011}\n'

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							, _KWARGS_DESCRIPTION				)
class 				a  (	datasets.Metric				):


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return datasets.MetricInfo(
										    description=_DESCRIPTION						,					citation=_CITATION						,					inputs_description=_KWARGS_DESCRIPTION						,					features=datasets.Features(
										        {
										            "predictions": datasets.Sequence(datasets.Value("int32"	)	),
										            "references": datasets.Sequence(datasets.Value("int32"	)	),
										        }
										        if self.config_name == "multilabel"
										        else {
										            "predictions": datasets.Value("int32"	),
										            "references": datasets.Value("int32"	),
										        }	)						,					reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html"]						,					)





						def        _UpperCAmelCase				(       self						,					A_						,					A_						,					A_=None						,					A_=1						,					A_="binary"						,					A_=None						,					A_="warn"						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		Union[str, Any] 		=    recall_score(
										    A_						,					A_						,					labels=A_						,					pos_label=A_						,					average=A_						,					sample_weight=A_						,					zero_division=A_						,					)
										return {"recall": float(A_	) if score.size == 1 else score}





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional

from packaging import version


if TYPE_CHECKING:
					from ... import PreTrainedTokenizer, TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import is_torch_available, logging


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_        =      {
    'bigscience/bloom': 'https://huggingface.co/bigscience/bloom/resolve/main/config.json',
    'bigscience/bloom-560m': 'https://huggingface.co/bigscience/bloom-560m/blob/main/config.json',
    'bigscience/bloom-1b1': 'https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json',
    'bigscience/bloom-1b7': 'https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json',
    'bigscience/bloom-3b': 'https://huggingface.co/bigscience/bloom-3b/blob/main/config.json',
    'bigscience/bloom-7b1': 'https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json',
}

class 				a  (	UpperCAmelCase				):
						_lowercase    						=			"bloom"
						_lowercase    						=			["past_key_values"]
						_lowercase    						=			{
						    "num_hidden_layers": "n_layer",
						    "num_attention_heads": "n_head",
						}


						def __init__(       self						,					A_=250880						,					A_=64						,					A_=2						,					A_=8						,					A_=1e-5						,					A_=0.02						,					A_=True						,					A_=1						,					A_=2						,					A_=False						,					A_=0.0						,					A_=0.0						,					A_=1						,					A_=False						,					**A_						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		List[str] 		=    vocab_size
										# Backward compatibility with n_embed kwarg
										_UpperCAmelCase       :		str 		=    kwargs.pop("n_embed"						,					A_	)
										_UpperCAmelCase       :		List[Any] 		=    hidden_size if n_embed is None else n_embed
										_UpperCAmelCase       :		Dict 		=    n_layer
										_UpperCAmelCase       :		Optional[Any] 		=    n_head
										_UpperCAmelCase       :		Optional[Any] 		=    layer_norm_epsilon
										_UpperCAmelCase       :		List[Any] 		=    initializer_range
										_UpperCAmelCase       :		Union[str, Any] 		=    use_cache
										_UpperCAmelCase       :		List[str] 		=    pretraining_tp
										_UpperCAmelCase       :		List[Any] 		=    apply_residual_connection_post_layernorm
										_UpperCAmelCase       :		int 		=    hidden_dropout
										_UpperCAmelCase       :		List[str] 		=    attention_dropout

										_UpperCAmelCase       :		int 		=    bos_token_id
										_UpperCAmelCase       :		str 		=    eos_token_id
										_UpperCAmelCase       :		Optional[Any] 		=    slow_but_exact

										super().__init__(bos_token_id=A_						,					eos_token_id=A_						,					**A_	)







class 				a  (	UpperCAmelCase				):
						_lowercase    						=			version.parse("1.12"				)


						def __init__(       self						,					A_						,					A_ = "default"						,					A_ = None						,					A_ = False						,					):







										'''simple docstring'''


										super().__init__(A_						,					task=A_						,					patching_specs=A_						,					use_past=A_	)
										if not getattr(self._config						,					"pad_token_id"						,					A_	):
														# TODO: how to do that better?
														_UpperCAmelCase       :		str 		=    0


						@property
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[Any] 		=    OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}	)
										if self.use_past:
														# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
														self.fill_with_past_key_values_(A_						,					direction="inputs"						,					inverted_values_shape=A_	)
														_UpperCAmelCase       :		Optional[int] 		=    {0: "batch", 1: "past_sequence + sequence"}
										else:
														_UpperCAmelCase       :		Union[str, Any] 		=    {0: "batch", 1: "sequence"}

										return common_inputs


						@property
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return self._config.n_layer


						@property
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return self._config.n_head


						@property
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return 1e-3


						def        _UpperCAmelCase				(       self						,					A_						,					A_ = -1						,					A_ = -1						,					A_ = False						,					A_ = None						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		int 		=    super(A_						,					self	).generate_dummy_inputs(
										    A_						,					batch_size=A_						,					seq_length=A_						,					is_pair=A_						,					framework=A_	)

										# We need to order the input in the way they appears in the forward()
										_UpperCAmelCase       :		Tuple 		=    OrderedDict({"input_ids": common_inputs["input_ids"]}	)

										# Need to add the past_keys
										if self.use_past:
														if not is_torch_available():
																		raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."	)
														else:
																		import torch

																		_UpperCAmelCase		,							_UpperCAmelCase       :		Union[str, Any] 		=    common_inputs["input_ids"].shape
																		# Not using the same length for past_key_values
																		_UpperCAmelCase       :		List[Any] 		=    seqlen + 2
																		_UpperCAmelCase       :		Dict 		=    self._config.hidden_size // self.num_attention_heads
																		_UpperCAmelCase       :		List[Any] 		=    (
																		    batch * self.num_attention_heads,
																		    head_dim,
																		    past_key_values_length,
																		)
																		_UpperCAmelCase       :		Optional[Any] 		=    (
																		    batch * self.num_attention_heads,
																		    past_key_values_length,
																		    head_dim,
																		)
																		_UpperCAmelCase       :		Tuple 		=    [
																		    (torch.zeros(A_	), torch.zeros(A_	)) for _ in range(self.num_layers	)
																		]

										_UpperCAmelCase       :		int 		=    common_inputs["attention_mask"]
										if self.use_past:
														_UpperCAmelCase       :		str 		=    ordered_inputs["attention_mask"].dtype
														_UpperCAmelCase       :		Optional[int] 		=    torch.cat(
														    [ordered_inputs["attention_mask"], torch.ones(A_						,					A_						,					dtype=A_	)]						,					dim=1	)

										return ordered_inputs





						@property
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										return 13


