





'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roberta import RobertaTokenizer


__UpperCamelCase					    =	logging.get_logger(__name__)

__UpperCamelCase					    =	{"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

__UpperCamelCase					    =	{
    "vocab_file": {
        "roberta-base": "https://huggingface.co/roberta-base/resolve/main/vocab.json",
        "roberta-large": "https://huggingface.co/roberta-large/resolve/main/vocab.json",
        "roberta-large-mnli": "https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json",
        "distilroberta-base": "https://huggingface.co/distilroberta-base/resolve/main/vocab.json",
        "roberta-base-openai-detector": "https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json",
        "roberta-large-openai-detector": (
            "https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json"
        ),
    },
    "merges_file": {
        "roberta-base": "https://huggingface.co/roberta-base/resolve/main/merges.txt",
        "roberta-large": "https://huggingface.co/roberta-large/resolve/main/merges.txt",
        "roberta-large-mnli": "https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt",
        "distilroberta-base": "https://huggingface.co/distilroberta-base/resolve/main/merges.txt",
        "roberta-base-openai-detector": "https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt",
        "roberta-large-openai-detector": (
            "https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt"
        ),
    },
    "tokenizer_file": {
        "roberta-base": "https://huggingface.co/roberta-base/resolve/main/tokenizer.json",
        "roberta-large": "https://huggingface.co/roberta-large/resolve/main/tokenizer.json",
        "roberta-large-mnli": "https://huggingface.co/roberta-large-mnli/resolve/main/tokenizer.json",
        "distilroberta-base": "https://huggingface.co/distilroberta-base/resolve/main/tokenizer.json",
        "roberta-base-openai-detector": (
            "https://huggingface.co/roberta-base-openai-detector/resolve/main/tokenizer.json"
        ),
        "roberta-large-openai-detector": (
            "https://huggingface.co/roberta-large-openai-detector/resolve/main/tokenizer.json"
        ),
    },
}

__UpperCamelCase					    =	{
    "roberta-base": 512,
    "roberta-large": 512,
    "roberta-large-mnli": 512,
    "distilroberta-base": 512,
    "roberta-base-openai-detector": 512,
    "roberta-large-openai-detector": 512,
}




class  _A (					__lowercase		):
		lowercase__:   List[str]				     =   VOCAB_FILES_NAMES
		lowercase__:   str				     =   PRETRAINED_VOCAB_FILES_MAP
		lowercase__:   List[str]				     =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		lowercase__:   List[str]				     =   ['''input_ids''', '''attention_mask''']
		lowercase__:   Optional[int]				     =   RobertaTokenizer

		def __init__(   self					:   List[str]  ,      __magic_name__					:   Any=None  ,      __magic_name__					:   Dict=None  ,      __magic_name__					:   List[str]=None  ,      __magic_name__					:   Any="replace"  ,      __magic_name__					:   int="<s>"  ,      __magic_name__					:   Union[str, Any]="</s>"  ,      __magic_name__					:   Any="</s>"  ,      __magic_name__					:   List[Any]="<s>"  ,      __magic_name__					:   Optional[int]="<unk>"  ,      __magic_name__					:   Any="<pad>"  ,      __magic_name__					:   str="<mask>"  ,      __magic_name__					:   int=False  ,      __magic_name__					:   Optional[Any]=True  ,      **__magic_name__					:   str  ,      )					->    Optional[Any]:


					"""simple docstring"""

					super().__init__(
					    __magic_name__  ,      __magic_name__  ,      tokenizer_file=__magic_name__  ,      errors=__magic_name__  ,      bos_token=__magic_name__  ,      eos_token=__magic_name__  ,      sep_token=__magic_name__  ,      cls_token=__magic_name__  ,      unk_token=__magic_name__  ,      pad_token=__magic_name__  ,      mask_token=__magic_name__  ,      add_prefix_space=__magic_name__  ,      trim_offsets=__magic_name__  ,      **__magic_name__  ,      )

					__snake_case					:      List[str]							      =     json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()			)
					if pre_tok_state.get("""add_prefix_space"""  ,      __magic_name__			) != add_prefix_space:
								__snake_case					:      Union[str, Any]							      =     getattr(__magic_name__  ,      pre_tok_state.pop("""type"""			)			)
								__snake_case					:      Optional[Any]							      =     add_prefix_space
								__snake_case					:      List[str]							      =     pre_tok_class(**__magic_name__			)

					__snake_case					:      int							      =     add_prefix_space

					__snake_case					:      Dict							      =     """post_processor"""
					__snake_case					:      List[Any]							      =     getattr(self.backend_tokenizer  ,      __magic_name__  ,      __magic_name__			)
					if tokenizer_component_instance:
								__snake_case					:      str							      =     json.loads(tokenizer_component_instance.__getstate__()			)

								# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
								if "sep" in state:
											__snake_case					:      Optional[Any]							      =     tuple(state["""sep"""]			)
								if "cls" in state:
											__snake_case					:      str							      =     tuple(state["""cls"""]			)

								__snake_case					:      Optional[int]							      =     False

								if state.get("""add_prefix_space"""  ,      __magic_name__			) != add_prefix_space:
											__snake_case					:      Union[str, Any]							      =     add_prefix_space
											__snake_case					:      List[str]							      =     True

								if state.get("""trim_offsets"""  ,      __magic_name__			) != trim_offsets:
											__snake_case					:      List[str]							      =     trim_offsets
											__snake_case					:      Any							      =     True

								if changes_to_apply:
											__snake_case					:      Tuple							      =     getattr(__magic_name__  ,      state.pop("""type"""			)			)
											__snake_case					:      str							      =     component_class(**__magic_name__			)
											setattr(self.backend_tokenizer  ,      __magic_name__  ,      __magic_name__			)

		@property
		def 	lowercase__     (   self					:   Union[str, Any]			)					->    str:


					"""simple docstring"""

					if self._mask_token is None:
								if self.verbose:
											logger.error("""Using mask_token, but it is not set yet."""			)
								return None
					return str(self._mask_token			)

		@mask_token.setter
		def 	lowercase__     (   self					:   Optional[Any]  ,      __magic_name__					:   List[str]			)					->    Dict:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     AddedToken(__magic_name__  ,      lstrip=__magic_name__  ,      rstrip=__magic_name__			) if isinstance(__magic_name__  ,      __magic_name__			) else value
					__snake_case					:      List[Any]							      =     value

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


					"""simple docstring"""

					__snake_case					:      Any							      =     kwargs.get("""is_split_into_words"""  ,      __magic_name__			)
					assert self.add_prefix_space or not is_split_into_words, (
					    f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
					    "to use it with pretokenized inputs."
					)

					return super()._batch_encode_plus(*__magic_name__  ,      **__magic_name__			)

		def 	lowercase__     (   self					:   List[Any]  ,      *__magic_name__					:   Any  ,      **__magic_name__					:   Optional[Any]			)					->    BatchEncoding:


					"""simple docstring"""

					__snake_case					:      List[str]							      =     kwargs.get("""is_split_into_words"""  ,      __magic_name__			)

					assert self.add_prefix_space or not is_split_into_words, (
					    f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
					    "to use it with pretokenized inputs."
					)

					return super()._encode_plus(*__magic_name__  ,      **__magic_name__			)

		def 	lowercase__     (   self					:   Dict  ,      __magic_name__					:   str  ,      __magic_name__					:   Optional[str] = None			)					->    Tuple[str]:


					"""simple docstring"""

					__snake_case					:      int							      =     self._tokenizer.model.save(__magic_name__  ,      name=__magic_name__			)
					return tuple(__magic_name__			)

		def 	lowercase__     (   self					:   Optional[Any]  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   Dict=None			)					->    Dict:


					"""simple docstring"""

					__snake_case					:      Optional[Any]							      =     [self.bos_token_id] + token_ids_a + [self.eos_token_id]
					if token_ids_a is None:
								return output

					return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]

		def 	lowercase__     (   self					:   List[str]  ,      __magic_name__					:   List[int]  ,      __magic_name__					:   Optional[List[int]] = None			)					->    List[int]:


					"""simple docstring"""

					__snake_case					:      List[str]							      =     [self.sep_token_id]
					__snake_case					:      Optional[Any]							      =     [self.cls_token_id]

					if token_ids_a is None:
								return len(cls + token_ids_a + sep			) * [0]
					return len(cls + token_ids_a + sep + sep + token_ids_a + sep			) * [0]









'''simple docstring'''






from sklearn.metrics import recall_score

import datasets


__UpperCamelCase					    =	"\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"


__UpperCamelCase					    =	"\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"


__UpperCamelCase					    =	"\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 	lowercase__     (   self					:   Optional[int]			)					->    Any:


					"""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 	lowercase__     (   self					:   Tuple  ,      __magic_name__					:   int  ,      __magic_name__					:   Union[str, Any]  ,      __magic_name__					:   Any=None  ,      __magic_name__					:   Optional[Any]=1  ,      __magic_name__					:   List[str]="binary"  ,      __magic_name__					:   Tuple=None  ,      __magic_name__					:   Dict="warn"  ,      )					->    Any:


					"""simple docstring"""

					__snake_case					:      Tuple							      =     recall_score(
					    __magic_name__  ,      __magic_name__  ,      labels=__magic_name__  ,      pos_label=__magic_name__  ,      average=__magic_name__  ,      sample_weight=__magic_name__  ,      zero_division=__magic_name__  ,      )
					return {"recall": float(__magic_name__			) if score.size == 1 else score}


