


from typing import Dict, List, Optional

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_A		:				str									=       logging.get_logger(__name__)


_A		:				int									=       {
    '''nielsr/canine-s''': 2_048,
}

# Unicode defines 1,114,112 total “codepoints”
_A		:				List[Any]									=       1_114_112

# Below: Constants defining canonical codepoints for special, pseudo-characters.
# Copied from https://github.com/google-research/language/blob/master/language/canine/special_codepoints.py
_A		:				Union[str, Any]									=       0

_A		:				int									=       0XE000
_A		:				List[str]									=       0XE001
_A		:				Tuple									=       0XE002
_A		:				Tuple									=       0XE003
_A		:				List[str]									=       0XE004

# Maps special codepoints to human-readable names.
_A		:				Dict[int, str]									=       {
    # Special symbols are represented using codepoints values that are valid,
    # but designated as "Private Use", meaning that they will never be assigned
    # characters by the Unicode Consortium, and are thus safe for use here.
    #
    # NOTE: Do *NOT* add any sort of [UNK_CHAR] here. They are explicitly
    # excluded and should fail with a hard error.
    CLS: "[CLS]",
    SEP: "[SEP]",
    BOS: "[BOS]",
    MASK: "[MASK]",
    PAD: "[PAD]",
    RESERVED: "[RESERVED]",
}

# Maps special codepoint human-readable names to their codepoint values.
_A		:				Dict[str, int]									=       {name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}



class        a					(			_UpperCAmelCase   ):
     UpperCAmelCase__ :  Optional[Any]						      =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





     def __init__(    self					:				Tuple    ,	SCREAMING_SNAKE_CASE_					:				Dict=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				str=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				Dict=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				int=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				List[Any]=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]=chr(SCREAMING_SNAKE_CASE_							)    ,	SCREAMING_SNAKE_CASE_					:				str=False    ,	SCREAMING_SNAKE_CASE_					:				Any=2048    ,	**SCREAMING_SNAKE_CASE_					:				str    ,	):
        __lowerCamelCase:				Union[str, Any]     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else bos_token
        __lowerCamelCase:				Tuple     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else eos_token
        __lowerCamelCase:				Union[str, Any]     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else sep_token
        __lowerCamelCase:				Optional[int]     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else cls_token
        __lowerCamelCase:				Union[str, Any]     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else pad_token

        # Mask token behave like a normal word, i.e. include the space before it
        __lowerCamelCase:				str     =	AddedToken(SCREAMING_SNAKE_CASE_    ,	lstrip=SCREAMING_SNAKE_CASE_    ,	rstrip=SCREAMING_SNAKE_CASE_							) if isinstance(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							) else mask_token

        super().__init__(
            bos_token=SCREAMING_SNAKE_CASE_    ,	eos_token=SCREAMING_SNAKE_CASE_    ,	sep_token=SCREAMING_SNAKE_CASE_    ,	cls_token=SCREAMING_SNAKE_CASE_    ,	pad_token=SCREAMING_SNAKE_CASE_    ,	mask_token=SCREAMING_SNAKE_CASE_    ,	add_prefix_space=SCREAMING_SNAKE_CASE_    ,	model_max_length=SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_    ,	)

        # Creates a mapping for looking up the IDs of special symbols.
        __lowerCamelCase:				Dict[str, int]     =	{}
        for codepoint, name in SPECIAL_CODEPOINTS.items():
           __lowerCamelCase:				Optional[Any]     =	codepoint

        # Creates a mapping for looking up the string forms of special symbol IDs.
        __lowerCamelCase:				Dict[int, str]     =	{
            codepoint: name for name, codepoint in self._special_codepoints.items()
        }

        __lowerCamelCase:				List[Any]     =	UNICODE_VOCAB_SIZE
        __lowerCamelCase:				List[Any]     =	len(self._special_codepoints							)





     @property
     def  SCREAMING_SNAKE_CASE__       (    self					:				Dict							):
        return self._unicode_vocab_size





     def  SCREAMING_SNAKE_CASE__       (    self					:				List[Any]    ,	SCREAMING_SNAKE_CASE_					:				str							):
        return list(SCREAMING_SNAKE_CASE_							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				List[Any]    ,	SCREAMING_SNAKE_CASE_					:				str							):
        try:
           return ord(SCREAMING_SNAKE_CASE_							)
        except TypeError:
           raise ValueError(F'invalid token: \'{token}\''							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Any    ,	SCREAMING_SNAKE_CASE_					:				int							):
        try:
           if index in SPECIAL_CODEPOINTS:
              return SPECIAL_CODEPOINTS[index]
           return chr(SCREAMING_SNAKE_CASE_							)
        except TypeError:
           raise ValueError(F'invalid id: {index}'							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[int]    ,	SCREAMING_SNAKE_CASE_					:				Optional[int]							):
        return "".join(SCREAMING_SNAKE_CASE_							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Any    ,	SCREAMING_SNAKE_CASE_					:				List[int]    ,	SCREAMING_SNAKE_CASE_					:				Optional[List[int]] = None							):
        __lowerCamelCase:				Tuple     =	[self.sep_token_id]
        __lowerCamelCase:				Any     =	[self.cls_token_id]

        __lowerCamelCase:				Union[str, Any]     =	cls + token_ids_a + sep
        if token_ids_a is not None:
           result += token_ids_a + sep
        return result





     def  SCREAMING_SNAKE_CASE__       (    self					:				Union[str, Any]    ,	SCREAMING_SNAKE_CASE_					:				List[int]    ,	SCREAMING_SNAKE_CASE_					:				Optional[List[int]] = None    ,	SCREAMING_SNAKE_CASE_					:				bool = False							):
        if already_has_special_tokens:
           return super().get_special_tokens_mask(
               token_ids_a=SCREAMING_SNAKE_CASE_    ,	token_ids_a=SCREAMING_SNAKE_CASE_    ,	already_has_special_tokens=SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				str     =	[1] + ([0] * len(SCREAMING_SNAKE_CASE_							)) + [1]
        if token_ids_a is not None:
           result += ([0] * len(SCREAMING_SNAKE_CASE_							)) + [1]
        return result





     def  SCREAMING_SNAKE_CASE__       (    self					:				Tuple    ,	SCREAMING_SNAKE_CASE_					:				List[int]    ,	SCREAMING_SNAKE_CASE_					:				Optional[List[int]] = None							):
        __lowerCamelCase:				Optional[Any]     =	[self.sep_token_id]
        __lowerCamelCase:				List[str]     =	[self.cls_token_id]

        __lowerCamelCase:				List[Any]     =	len(cls + token_ids_a + sep							) * [0]
        if token_ids_a is not None:
           result += len(token_ids_a + sep							) * [1]
        return result







     def  SCREAMING_SNAKE_CASE__       (    self					:				Dict    ,	SCREAMING_SNAKE_CASE_					:				str    ,	SCREAMING_SNAKE_CASE_					:				Optional[str] = None							):
        return ()






from sklearn.metrics import fa_score

import datasets


_A		:				Any									=       '''
The F1 score is the harmonic mean of the precision and recall. It can be computed with the equation:
F1 = 2 * (precision * recall) / (precision + recall)
'''


_A		:				Dict									=       '''
Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    labels (`list` of `int`): The set of labels to include when `average` is not set to `\'binary\'`, and the order of the labels if `average` is `None`. Labels present in the data can be excluded, for example to calculate a multiclass average ignoring a majority negative class. 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 `predictions` and `references` are used in sorted order. Defaults to None.
    pos_label (`int`): The class to be considered the positive class, in the case where `average` is set to `binary`. Defaults to 1.
    average (`string`): This parameter is required for multiclass/multilabel targets. If set to `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 classes found in `predictions` and `references` 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. This option 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.

Returns:
    f1 (`float` or `array` of `float`): F1 score or list of f1 scores, depending on the value passed to `average`. Minimum possible value is 0. Maximum possible value is 1. Higher f1 scores are better.

Examples:

    Example 1-A simple binary example
        >>> f1_metric = datasets.load_metric("f1")
        >>> results = f1_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0])
        >>> print(results)
        {\'f1\': 0.5}

    Example 2-The same simple binary example as in Example 1, but with `pos_label` set to `0`.
        >>> f1_metric = datasets.load_metric("f1")
        >>> results = f1_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0], pos_label=0)
        >>> print(round(results[\'f1\'], 2))
        0.67

    Example 3-The same simple binary example as in Example 1, but with `sample_weight` included.
        >>> f1_metric = datasets.load_metric("f1")
        >>> results = f1_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0], sample_weight=[0.9, 0.5, 3.9, 1.2, 0.3])
        >>> print(round(results[\'f1\'], 2))
        0.35

    Example 4-A multiclass example, with different values for the `average` input.
        >>> predictions = [0, 2, 1, 0, 0, 1]
        >>> references = [0, 1, 2, 0, 1, 2]
        >>> results = f1_metric.compute(predictions=predictions, references=references, average="macro")
        >>> print(round(results[\'f1\'], 2))
        0.27
        >>> results = f1_metric.compute(predictions=predictions, references=references, average="micro")
        >>> print(round(results[\'f1\'], 2))
        0.33
        >>> results = f1_metric.compute(predictions=predictions, references=references, average="weighted")
        >>> print(round(results[\'f1\'], 2))
        0.27
        >>> results = f1_metric.compute(predictions=predictions, references=references, average=None)
        >>> print(results)
        {\'f1\': array([0.8, 0. , 0. ])}
'''


_A		:				Union[str, Any]									=       '''
@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  SCREAMING_SNAKE_CASE__       (    self					:				Union[str, Any]							):
        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.f1_score.html"""]    ,	)







     def  SCREAMING_SNAKE_CASE__       (    self					:				int    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				str    ,	SCREAMING_SNAKE_CASE_					:				str=None    ,	SCREAMING_SNAKE_CASE_					:				str=1    ,	SCREAMING_SNAKE_CASE_					:				List[str]="binary"    ,	SCREAMING_SNAKE_CASE_					:				List[str]=None							):
        __lowerCamelCase:				str     =	fa_score(
            SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	labels=SCREAMING_SNAKE_CASE_    ,	pos_label=SCREAMING_SNAKE_CASE_    ,	average=SCREAMING_SNAKE_CASE_    ,	sample_weight=SCREAMING_SNAKE_CASE_							)
        return {"f1": float(SCREAMING_SNAKE_CASE_							) if score.size == 1 else score}


