



'''simple docstring'''




import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    BioGptForCausalLM,
						    BioGptForSequenceClassification,
						    BioGptForTokenClassification,
						    BioGptModel,
						    BioGptTokenizer,
						)
						from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST







class 	_lowerCAmelCase							:


	def __init__(self       ,      lowercase       ,      lowercase=13       ,      lowercase=7       ,      lowercase=True       ,      lowercase=True       ,      lowercase=False       ,      lowercase=True       ,      lowercase=99       ,      lowercase=32       ,      lowercase=5       ,      lowercase=4       ,      lowercase=37       ,      lowercase="gelu"       ,      lowercase=0.1       ,      lowercase=0.1       ,      lowercase=512       ,      lowercase=16       ,      lowercase=2       ,      lowercase=0.02       ,      lowercase=3       ,      lowercase=4       ,      lowercase=None       ,      ):
				A_	:						int	=     parent
				A_	:						Dict	=     batch_size
				A_	:						str	=     seq_length
				A_	:						List[Any]	=     is_training
				A_	:						List[str]	=     use_input_mask
				A_	:						Optional[int]	=     use_token_type_ids
				A_	:						Optional[int]	=     use_labels
				A_	:						int	=     vocab_size
				A_	:						Tuple	=     hidden_size
				A_	:						List[Any]	=     num_hidden_layers
				A_	:						int	=     num_attention_heads
				A_	:						List[str]	=     intermediate_size
				A_	:						Dict	=     hidden_act
				A_	:						List[str]	=     hidden_dropout_prob
				A_	:						List[Any]	=     attention_probs_dropout_prob
				A_	:						int	=     max_position_embeddings
				A_	:						Optional[int]	=     type_vocab_size
				A_	:						Dict	=     type_sequence_label_size
				A_	:						Tuple	=     initializer_range
				A_	:						List[Any]	=     num_labels
				A_	:						Optional[int]	=     num_choices
				A_	:						str	=     scope


	def     _a	(self							):
				A_	:						List[str]	=     ids_tensor([self.batch_size, self.seq_length]       ,      self.vocab_size							)

				A_	:						Any	=     None
				if self.use_input_mask:
							A_	:						str	=     random_attention_mask([self.batch_size, self.seq_length]							)

				A_	:						Union[str, Any]	=     None
				if self.use_token_type_ids:
							A_	:						List[Any]	=     ids_tensor([self.batch_size, self.seq_length]       ,      self.type_vocab_size							)

				A_	:						Optional[int]	=     None
				A_	:						Optional[Any]	=     None
				A_	:						str	=     None
				if self.use_labels:
							A_	:						List[str]	=     ids_tensor([self.batch_size]       ,      self.type_sequence_label_size							)
							A_	:						Optional[int]	=     ids_tensor([self.batch_size, self.seq_length]       ,      self.num_labels							)
							A_	:						List[Any]	=     ids_tensor([self.batch_size]       ,      self.num_choices							)

				A_	:						Optional[Any]	=     self.get_config()

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


	def     _a	(self							):
				return BioGptConfig(
				    vocab_size=self.vocab_size       ,      hidden_size=self.hidden_size       ,      num_hidden_layers=self.num_hidden_layers       ,      num_attention_heads=self.num_attention_heads       ,      intermediate_size=self.intermediate_size       ,      hidden_act=self.hidden_act       ,      hidden_dropout_prob=self.hidden_dropout_prob       ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,      max_position_embeddings=self.max_position_embeddings       ,      type_vocab_size=self.type_vocab_size       ,      is_decoder=__lowerCAmelCase       ,      initializer_range=self.initializer_range       ,      )


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase							):
				A_	:						Optional[int]	=     BioGptModel(config=__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()
				A_	:						int	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase							)
				A_	:						Any	=     model(__lowerCAmelCase							)
				self.parent.assertEqual(result.last_hidden_state.shape       ,      (self.batch_size, self.seq_length, self.hidden_size)							)


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      ):
				A_	:						Optional[Any]	=     BioGptForCausalLM(config=__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()
				A_	:						str	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      token_type_ids=__lowerCAmelCase       ,      labels=__lowerCAmelCase							)
				self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.vocab_size)							)


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      *lowercase							):
				A_	:						Optional[int]	=     BioGptModel(config=__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()

				# create attention mask
				A_	:						Optional[Any]	=     torch.ones(input_ids.shape       ,      dtype=torch.long       ,      device=__lowerCAmelCase							)
				A_	:						Tuple	=     self.seq_length // 2
				A_	:						List[Any]	=     0

				# first forward pass
				A_,    A_	:						int	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase							).to_tuple()

				# create hypothetical next token and extent to next_input_ids
				A_	:						Optional[int]	=     ids_tensor((self.batch_size, 1)       ,      config.vocab_size							)

				# change a random masked slice from input_ids
				A_	:						List[Any]	=     ids_tensor((1,)       ,      __lowerCAmelCase							).item() + 1
				A_	:						Dict	=     ids_tensor((self.batch_size, 1)       ,      config.vocab_size							).squeeze(-1							)
				A_	:						List[str]	=     random_other_next_tokens

				# append to next input_ids and attn_mask
				A_	:						Optional[Any]	=     torch.cat([input_ids, next_tokens]       ,      dim=-1							)
				A_	:						List[str]	=     torch.cat(
				    [attn_mask, torch.ones((attn_mask.shape[0], 1)       ,      dtype=torch.long       ,      device=__lowerCAmelCase							)]       ,      dim=1       ,      )

				# get two different outputs
				A_	:						Union[str, Any]	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase							)["""last_hidden_state"""]
				A_	:						Any	=     model(__lowerCAmelCase       ,      past_key_values=__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase							)["""last_hidden_state"""]

				# select random slice
				A_	:						Optional[int]	=     ids_tensor((1,)       ,      output_from_past.shape[-1]							).item()
				A_	:						str	=     output_from_no_past[:, -1, random_slice_idx].detach()
				A_	:						Any	=     output_from_past[:, 0, random_slice_idx].detach()

				# test that outputs are equal for slice
				self.parent.assertTrue(torch.allclose(__lowerCAmelCase       ,      __lowerCAmelCase       ,      atol=1E-3							)							)


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      *lowercase							):
				A_	:						List[str]	=     BioGptModel(config=__lowerCAmelCase							).to(__lowerCAmelCase							).eval()

				A_	:						Union[str, Any]	=     torch.ones(input_ids.shape       ,      dtype=torch.long       ,      device=__lowerCAmelCase							)

				# first forward pass
				A_	:						Any	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      use_cache=__lowerCAmelCase							)

				A_,    A_	:						Union[str, Any]	=     outputs.to_tuple()

				# create hypothetical multiple next token and extent to next_input_ids
				A_	:						str	=     ids_tensor((self.batch_size, 3)       ,      config.vocab_size							)
				A_	:						Dict	=     ids_tensor((self.batch_size, 3)       ,      2							)

				# append to next input_ids and
				A_	:						int	=     torch.cat([input_ids, next_tokens]       ,      dim=-1							)
				A_	:						List[str]	=     torch.cat([attention_mask, next_attn_mask]       ,      dim=-1							)

				A_	:						Tuple	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase							)["""last_hidden_state"""]
				A_	:						Dict	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      past_key_values=__lowerCAmelCase							)[
				    """last_hidden_state"""
				]

				# select random slice
				A_	:						Any	=     ids_tensor((1,)       ,      output_from_past.shape[-1]							).item()
				A_	:						Dict	=     output_from_no_past[:, -3:, random_slice_idx].detach()
				A_	:						Dict	=     output_from_past[:, :, random_slice_idx].detach()

				self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]							)

				# test that outputs are equal for slice
				self.parent.assertTrue(torch.allclose(__lowerCAmelCase       ,      __lowerCAmelCase       ,      atol=1E-3							)							)


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      *lowercase       ,      lowercase=False							):
				A_	:						Any	=     BioGptForCausalLM(__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				if gradient_checkpointing:
							model.gradient_checkpointing_enable()

				A_	:						Dict	=     model(__lowerCAmelCase       ,      labels=__lowerCAmelCase							)
				self.parent.assertEqual(result.loss.shape       ,      ()							)
				self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.vocab_size)							)
				result.loss.backward()


	def     _a	(self       ,      lowercase       ,      *lowercase							):
				A_	:						str	=     BioGptModel(__lowerCAmelCase							)
				A_	:						Optional[int]	=     model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers							)
				for key in model.state_dict().keys():
							if "c_proj" in key and "weight" in key:
										self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]							) - model_std							)       ,      0.0_01							)
										self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]							) - 0.0							)       ,      0.01							)


	def     _a	(self       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      lowercase       ,      *lowercase							):
				A_	:						Optional[int]	=     self.num_labels
				A_	:						Optional[int]	=     BioGptForTokenClassification(__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()
				A_	:						Any	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      token_type_ids=__lowerCAmelCase							)
				self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.num_labels)							)


	def     _a	(self							):
				A_	:						str	=     self.prepare_config_and_inputs()
				(
				    (
				    A_ 
				),    (
				    A_ 
				),    (
				    A_ 
				),    (
				    A_ 
				),    (
				    A_ 
				),    (
				    A_ 
				),    (
				    A_ 
				),     
				)	:						Dict	=     config_and_inputs
				A_	:						str	=     {"""input_ids""": input_ids, """attention_mask""": input_mask}
				return config, inputs_dict







@require_torch
class 	_lowerCAmelCase							(			lowerCAmelCase_      ,			lowerCAmelCase_      ,			lowerCAmelCase_      ,			unittest.TestCase ):
	__SCREAMING_SNAKE_CASE   :		List[Any]					=					(
	    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
	    if is_torch_available()
	    else ()
	)
	__SCREAMING_SNAKE_CASE   :		Tuple					=					(BioGptForCausalLM,) if is_torch_available() else ()
	__SCREAMING_SNAKE_CASE   :		Optional[Any]					=					(
	    {
	        'feature-extraction': BioGptModel,
	        'text-classification': BioGptForSequenceClassification,
	        'text-generation': BioGptForCausalLM,
	        'token-classification': BioGptForTokenClassification,
	        'zero-shot': BioGptForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	__SCREAMING_SNAKE_CASE   :		int					=					False


	def     _a	(self							):
				A_	:						int	=     BioGptModelTester(self							)
				A_	:						List[str]	=     ConfigTester(self       ,      config_class=__lowerCAmelCase       ,      hidden_size=37							)


	def     _a	(self							):
				self.config_tester.run_common_tests()


	def     _a	(self							):
				A_	:						List[Any]	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						int	=     self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
							A_	:						Dict	=     type
							self.model_tester.create_and_check_model(*__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						Tuple	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						Dict	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_forward_and_backwards(*__lowerCAmelCase       ,      gradient_checkpointing=__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						int	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						Dict	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_weight_initialization(*__lowerCAmelCase							)


	def     _a	(self							):
				A_	:						str	=     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_for_token_classification(*__lowerCAmelCase							)


	@slow
	def     _a	(self							):
				A_	:						Dict	=     BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""							)
				model.to(__lowerCAmelCase							)
				A_	:						Optional[Any]	=     BioGptTokenizer.from_pretrained("""microsoft/biogpt"""							)

				A_	:						List[str]	=     """left"""

				# Define PAD Token = EOS Token = 50256
				A_	:						int	=     tokenizer.eos_token
				A_	:						str	=     model.config.eos_token_id

				# use different length sentences to test batching
				A_	:						Tuple	=     [
				    """Hello, my dog is a little""",
				    """Today, I""",
				]

				A_	:						List[str]	=     tokenizer(__lowerCAmelCase       ,      return_tensors="""pt"""       ,      padding=__lowerCAmelCase							)
				A_	:						Any	=     inputs["""input_ids"""].to(__lowerCAmelCase							)

				A_	:						Optional[int]	=     model.generate(
				    input_ids=__lowerCAmelCase       ,      attention_mask=inputs["""attention_mask"""].to(__lowerCAmelCase							)       ,      )

				A_	:						Optional[Any]	=     tokenizer(sentences[0]       ,      return_tensors="""pt"""							).input_ids.to(__lowerCAmelCase							)
				A_	:						Optional[int]	=     model.generate(input_ids=__lowerCAmelCase							)

				A_	:						Tuple	=     inputs_non_padded.shape[-1] - inputs["""attention_mask"""][-1].long().sum().cpu().item()
				A_	:						List[Any]	=     tokenizer(sentences[1]       ,      return_tensors="""pt"""							).input_ids.to(__lowerCAmelCase							)
				A_	:						Union[str, Any]	=     model.generate(input_ids=__lowerCAmelCase       ,      max_length=model.config.max_length - num_paddings							)

				A_	:						Any	=     tokenizer.batch_decode(__lowerCAmelCase       ,      skip_special_tokens=__lowerCAmelCase							)
				A_	:						Any	=     tokenizer.decode(output_non_padded[0]       ,      skip_special_tokens=__lowerCAmelCase							)
				A_	:						List[str]	=     tokenizer.decode(output_padded[0]       ,      skip_special_tokens=__lowerCAmelCase							)

				A_	:						Any	=     [
				    """Hello, my dog is a little bit bigger than a little bit.""",
				    """Today, I have a good idea of how to use the information""",
				]
				self.assertListEqual(__lowerCAmelCase       ,      __lowerCAmelCase							)
				self.assertListEqual(__lowerCAmelCase       ,      [non_padded_sentence, padded_sentence]							)


	@slow
	def     _a	(self							):
				for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A_	:						int	=     BioGptModel.from_pretrained(__lowerCAmelCase							)
							self.assertIsNotNone(__lowerCAmelCase							)


	def     _a	(self							):
				A_,    A_	:						Any	=     self.model_tester.prepare_config_and_inputs_for_common()
				A_	:						Tuple	=     3
				A_	:						Tuple	=     input_dict["""input_ids"""]
				A_	:						List[Any]	=     input_ids.ne(1							).to(__lowerCAmelCase							)
				A_	:						Optional[Any]	=     ids_tensor([self.model_tester.batch_size]       ,      self.model_tester.type_sequence_label_size							)
				A_	:						Optional[int]	=     BioGptForSequenceClassification(__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()
				A_	:						Dict	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      labels=__lowerCAmelCase							)
				self.assertEqual(result.logits.shape       ,      (self.model_tester.batch_size, self.model_tester.num_labels)							)


	def     _a	(self							):
				A_,    A_	:						Union[str, Any]	=     self.model_tester.prepare_config_and_inputs_for_common()
				A_	:						List[str]	=     3
				A_	:						List[Any]	=     """multi_label_classification"""
				A_	:						Dict	=     input_dict["""input_ids"""]
				A_	:						Any	=     input_ids.ne(1							).to(__lowerCAmelCase							)
				A_	:						Optional[int]	=     ids_tensor(
				    [self.model_tester.batch_size, config.num_labels]       ,      self.model_tester.type_sequence_label_size							).to(torch.float							)
				A_	:						List[str]	=     BioGptForSequenceClassification(__lowerCAmelCase							)
				model.to(__lowerCAmelCase							)
				model.eval()
				A_	:						Dict	=     model(__lowerCAmelCase       ,      attention_mask=__lowerCAmelCase       ,      labels=__lowerCAmelCase							)
				self.assertEqual(result.logits.shape       ,      (self.model_tester.batch_size, self.model_tester.num_labels)							)







@require_torch
class 	_lowerCAmelCase							(			unittest.TestCase ):


	@slow
	def     _a	(self							):
				A_	:						Optional[int]	=     BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""							)
				A_	:						Union[str, Any]	=     torch.tensor([[2, 4805, 9, 656, 21]]							)
				A_	:						Optional[Any]	=     model(__lowerCAmelCase							)[0]

				A_	:						List[Any]	=     42384

				A_	:						Union[str, Any]	=     torch.Size((1, 5, vocab_size)							)
				self.assertEqual(output.shape       ,      __lowerCAmelCase							)

				A_	:						Tuple	=     torch.tensor(
				    [[[-9.52_36, -9.89_18, 10.45_57], [-11.04_69, -9.64_23, 8.10_22], [-8.86_64, -7.88_26, 5.53_25]]]							)

				self.assertTrue(torch.allclose(output[:, :3, :3]       ,      __lowerCAmelCase       ,      atol=1E-4							)							)


	@slow
	def     _a	(self							):
				A_	:						List[str]	=     BioGptTokenizer.from_pretrained("""microsoft/biogpt"""							)
				A_	:						str	=     BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""							)
				model.to(__lowerCAmelCase							)

				torch.manual_seed(0							)
				A_	:						str	=     tokenizer("""COVID-19 is"""       ,      return_tensors="""pt"""							).to(__lowerCAmelCase							)
				A_	:						int	=     model.generate(
				    **__lowerCAmelCase       ,      min_length=100       ,      max_length=1024       ,      num_beams=5       ,      early_stopping=__lowerCAmelCase       ,      )
				A_	:						Tuple	=     tokenizer.decode(output_ids[0]       ,      skip_special_tokens=__lowerCAmelCase							)

				A_	:						Dict	=     (
				    """COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the"""
				    """ causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and"""
				    """ territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),"""
				    """ and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and"""
				    """ more than 800,000 deaths."""
				)
				self.assertEqual(__lowerCAmelCase       ,      __lowerCAmelCase							)
"""simple docstring"""


from sklearn.metrics import recall_score

import datasets


UpperCAmelCase__     						=  """
Recall is the fraction of the positive examples that were correctly labeled by the model as positive. It can be computed with the equation:
Recall = TP / (TP + FN)
Where TP is the true positives and FN is the false negatives.
"""


UpperCAmelCase__     						=  """
Args:
- **predictions** (`list` of `int`): The predicted labels.
- **references** (`list` of `int`): The ground truth labels.
- **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.
- **pos_label** (`int`): The class label to use as the 'positive class' when calculating the recall. Defaults to `1`.
- **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'`.
    - `'binary'`: Only report results for the class specified by `pos_label`. This is applicable only if the target labels and predictions are binary.
    - `'micro'`: Calculate metrics globally by counting the total true positives, false negatives, and false positives.
    - `'macro'`: Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
    - `'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.
    - `'samples'`: Calculate metrics for each instance, and find their average (only meaningful for multilabel classification).
- **sample_weight** (`list` of `float`): Sample weights Defaults to `None`.
- **zero_division** (): Sets the value to return when there is a zero division. Defaults to .
    - `'warn'`: If there is a zero division, the return value is `0`, but warnings are also raised.
    - `0`: If there is a zero division, the return value is `0`.
    - `1`: If there is a zero division, the return value is `1`.

Returns:
- **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.

Examples:

    Example 1-A simple example with some errors
        >>> recall_metric = datasets.load_metric('recall')
        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1])
        >>> print(results)
        {'recall': 0.6666666666666666}

    Example 2-The same example as Example 1, but with `pos_label=0` instead of the default `pos_label=1`.
        >>> recall_metric = datasets.load_metric('recall')
        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], pos_label=0)
        >>> print(results)
        {'recall': 0.5}

    Example 3-The same example as Example 1, but with `sample_weight` included.
        >>> recall_metric = datasets.load_metric('recall')
        >>> sample_weight = [0.9, 0.2, 0.9, 0.3, 0.8]
        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], sample_weight=sample_weight)
        >>> print(results)
        {'recall': 0.55}

    Example 4-A multiclass example, using different averages.
        >>> recall_metric = datasets.load_metric('recall')
        >>> predictions = [0, 2, 1, 0, 0, 1]
        >>> references = [0, 1, 2, 0, 1, 2]
        >>> results = recall_metric.compute(predictions=predictions, references=references, average='macro')
        >>> print(results)
        {'recall': 0.3333333333333333}
        >>> results = recall_metric.compute(predictions=predictions, references=references, average='micro')
        >>> print(results)
        {'recall': 0.3333333333333333}
        >>> results = recall_metric.compute(predictions=predictions, references=references, average='weighted')
        >>> print(results)
        {'recall': 0.3333333333333333}
        >>> results = recall_metric.compute(predictions=predictions, references=references, average=None)
        >>> print(results)
        {'recall': array([1., 0., 0.])}
"""


UpperCAmelCase__     						=  """
@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}
"""


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


    def    lowerCAmelCase_     (    self		:     Tuple    ):
      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    lowerCAmelCase_     (    self		:     List[Any]      , __lowerCAmelCase		:     int      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     int=None      , __lowerCAmelCase		:     Dict=1      , __lowerCAmelCase		:     List[str]="binary"      , __lowerCAmelCase		:     Any=None      , __lowerCAmelCase		:     int="warn"      , ):
      _UpperCAmelCase         =					recall_score(
          __lowerCAmelCase      , __lowerCAmelCase      , labels=__lowerCAmelCase      , pos_label=__lowerCAmelCase      , average=__lowerCAmelCase      , sample_weight=__lowerCAmelCase      , zero_division=__lowerCAmelCase      , )
      return {"recall": float(__lowerCAmelCase    ) if score.size == 1 else score}
