
import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
    from transformers.pipelines.conversational import Conversation


__lowerCAmelCase			:     List[Any]           =   logging.get_logger(__name__)

__lowerCAmelCase			:     List[str]           =   {'tokenizer_file': 'tokenizer.json'}

__lowerCAmelCase			:     Optional[Any]           =   {
    'tokenizer_file': {
        'bigscience/tokenizer': 'https://huggingface.co/bigscience/tokenizer/blob/main/tokenizer.json',
        'bigscience/bloom-560m': 'https://huggingface.co/bigscience/bloom-560m/blob/main/tokenizer.json',
        'bigscience/bloom-1b1': 'https://huggingface.co/bigscience/bloom-1b1/blob/main/tokenizer.json',
        'bigscience/bloom-1b7': 'https://huggingface.co/bigscience/bloom-1b7/blob/main/tokenizer.json',
        'bigscience/bloom-3b': 'https://huggingface.co/bigscience/bloom-3b/blob/main/tokenizer.json',
        'bigscience/bloom-7b1': 'https://huggingface.co/bigscience/bloom-7b1/blob/main/tokenizer.json',
        'bigscience/bloom': 'https://huggingface.co/bigscience/bloom/blob/main/tokenizer.json',
    },
}




class        UpperCAmelCase_			( _A     ):


  '''simple docstring'''







  a__           =		VOCAB_FILES_NAMES
  a__           =		PRETRAINED_VOCAB_FILES_MAP
  a__           =		["""input_ids""", """attention_mask"""]
  a__           =		None
  def __init__( self			: Optional[Any]			,							UpperCamelCase__			: List[str]=None			,							UpperCamelCase__			: Optional[int]=None			,							UpperCamelCase__			: str=None			,							UpperCamelCase__			: Optional[Any]="<unk>"			,							UpperCamelCase__			: Optional[Any]="<s>"			,							UpperCamelCase__			: List[str]="</s>"			,							UpperCamelCase__			: List[str]="<pad>"			,							UpperCamelCase__			: List[str]=False			,							UpperCamelCase__			: List[Any]=False			,							**UpperCamelCase__			: Dict			,							)			->	int:







    """simple docstring"""






    super().__init__(
        UpperCamelCase__			,							UpperCamelCase__			,							tokenizer_file=UpperCamelCase__			,							unk_token=UpperCamelCase__			,							bos_token=UpperCamelCase__			,							eos_token=UpperCamelCase__			,							pad_token=UpperCamelCase__			,							add_prefix_space=UpperCamelCase__			,							clean_up_tokenization_spaces=UpperCamelCase__			,							**UpperCamelCase__			,							)
    __magic_name__				     =       json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()    )
    if pre_tok_state.get("""add_prefix_space"""			,							UpperCamelCase__    ) != add_prefix_space:
      __magic_name__				     =       getattr(UpperCamelCase__			,							pre_tok_state.pop("""type"""    )    )
      __magic_name__				     =       add_prefix_space
      __magic_name__				     =       pre_tok_class(**UpperCamelCase__    )

    __magic_name__				     =       add_prefix_space
  def 							_lowercase							( self			: Optional[Any]			,							*UpperCamelCase__			: List[Any]			,							**UpperCamelCase__			: str    )			->	BatchEncoding:







    """simple docstring"""






    __magic_name__				     =       kwargs.get("""is_split_into_words"""			,							UpperCamelCase__    )
    if not (self.add_prefix_space or not is_split_into_words):
      raise Exception(
          F'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with'''
          """ pretokenized inputs."""    )

    return super()._batch_encode_plus(*UpperCamelCase__			,							**UpperCamelCase__    )
  def 							_lowercase							( self			: int			,							*UpperCamelCase__			: str			,							**UpperCamelCase__			: Union[str, Any]    )			->	BatchEncoding:







    """simple docstring"""






    __magic_name__				     =       kwargs.get("""is_split_into_words"""			,							UpperCamelCase__    )

    if not (self.add_prefix_space or not is_split_into_words):
      raise Exception(
          F'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with'''
          """ pretokenized inputs."""    )

    return super()._encode_plus(*UpperCamelCase__			,							**UpperCamelCase__    )
  def 							_lowercase							( self			: str			,							UpperCamelCase__			: str			,							UpperCamelCase__			: Optional[str] = None    )			->	Tuple[str]:







    """simple docstring"""






    __magic_name__				     =       self._tokenizer.model.save(UpperCamelCase__			,							name=UpperCamelCase__    )
    return tuple(UpperCamelCase__    )





  def 							_lowercase							( self			: Union[str, Any]			,							UpperCamelCase__			: "Conversation"    )			->	List[int]:







    """simple docstring"""






    __magic_name__				     =       []
    for is_user, text in conversation.iter_texts():
      input_ids.extend(self.encode(UpperCamelCase__			,							add_special_tokens=UpperCamelCase__    ) + [self.eos_token_id]    )

    if len(UpperCamelCase__    ) > self.model_max_length:
      __magic_name__				     =       input_ids[-self.model_max_length :]
    return input_ids



import re
import string

import numpy as np

import datasets


__lowerCAmelCase			:     Optional[int]           =   '\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

__lowerCAmelCase			:     Optional[int]           =   '\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

__lowerCAmelCase			:     Optional[int]           =   '\n'




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


  '''simple docstring'''







  def 							_lowercase							( self			: str    )			->	Optional[int]:







    """simple docstring"""






    return datasets.MetricInfo(
        description=_DESCRIPTION			,							citation=_CITATION			,							inputs_description=_KWARGS_DESCRIPTION			,							features=datasets.Features(
            {
                """predictions""": datasets.Value("""string"""			,							id="""sequence"""    ),
                """references""": datasets.Value("""string"""			,							id="""sequence"""    ),
            }    )			,							reference_urls=[]			,							)





  def 							_lowercase							( self			: Optional[int]			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: Optional[Any]=None			,							UpperCamelCase__			: Optional[Any]=False			,							UpperCamelCase__			: int=False			,							UpperCamelCase__			: Tuple=False			,							)			->	Dict:







    """simple docstring"""






    if regexes_to_ignore is not None:
      for s in regexes_to_ignore:
        __magic_name__				     =       np.array([re.sub(UpperCamelCase__			,							""""""			,							UpperCamelCase__    ) for x in predictions]    )
        __magic_name__				     =       np.array([re.sub(UpperCamelCase__			,							""""""			,							UpperCamelCase__    ) for x in references]    )
    else:
      __magic_name__				     =       np.asarray(UpperCamelCase__    )
      __magic_name__				     =       np.asarray(UpperCamelCase__    )

    if ignore_case:
      __magic_name__				     =       np.char.lower(UpperCamelCase__    )
      __magic_name__				     =       np.char.lower(UpperCamelCase__    )

    if ignore_punctuation:
      __magic_name__				     =       string.punctuation.maketrans(""""""			,							""""""			,							string.punctuation    )
      __magic_name__				     =       np.char.translate(UpperCamelCase__			,							table=UpperCamelCase__    )
      __magic_name__				     =       np.char.translate(UpperCamelCase__			,							table=UpperCamelCase__    )

    if ignore_numbers:
      __magic_name__				     =       string.digits.maketrans(""""""			,							""""""			,							string.digits    )
      __magic_name__				     =       np.char.translate(UpperCamelCase__			,							table=UpperCamelCase__    )
      __magic_name__				     =       np.char.translate(UpperCamelCase__			,							table=UpperCamelCase__    )

    __magic_name__				     =       predictions == references

    return {"exact_match": np.mean(UpperCamelCase__    ) * 100}

