
"""simple docstring"""





import json
import os
import unittest

from transformers.models.gptsan_japanese.tokenization_gptsan_japanese import (
    VOCAB_FILES_NAMES,
    GPTSanJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class A_	(lowercase__				,unittest.TestCase      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						str       =		GPTSanJapaneseTokenizer
  SCREAMING_SNAKE_CASE__			:						str       =		False
  SCREAMING_SNAKE_CASE__			:						int       =		{"""do_clean_text""": False, """add_prefix_space""": False}







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     super().setUp()

     # fmt: off
     UpperCAmelCase_					:					Optional[int]			     =    ["こん", "こんに", "にちは", "ばんは", "世界,㔺界", "、", "。", "<BR>", "<SP>", "<TAB>", "<URL>", "<EMAIL>", "<TEL>", "<DATE>", "<PRICE>", "<BLOCK>", "<KIGOU>", "<U2000U2BFF>", "<|emoji1|>", "<unk>", "<|bagoftoken|>", "<|endoftext|>"]
     # fmt: on
     UpperCAmelCase_					:					List[Any]			     =    {"emoji": {"\ud83d\ude00": "<|emoji1|>"}, "emoji_inv": {"<|emoji1|>": "\ud83d\ude00"}}  # 😀
     UpperCAmelCase_					:					Dict			     =    {"unk_token": "<unk>"}

     UpperCAmelCase_					:					Any			     =    os.path.join(self.tmpdirname				,   VOCAB_FILES_NAMES["vocab_file"]  )
     UpperCAmelCase_					:					Union[str, Any]			     =    os.path.join(self.tmpdirname				,   VOCAB_FILES_NAMES["emoji_file"]  )
     with open(self.vocab_file				,   "w"				,   encoding="utf-8"  ) as vocab_writer:
        vocab_writer.write("".join([x + "\n" for x in vocab_tokens]  )  )
     with open(self.emoji_file				,   "w"  ) as emoji_writer:
        emoji_writer.write(json.dumps(lowercase_  )  )







  def        UpperCamelCase__					(		self				,   **lowercase_  ):

     """simple docstring"""
     kwargs.update(self.special_tokens_map  )
     return GPTSanJapaneseTokenizer.from_pretrained(self.tmpdirname				,   **lowercase_  )







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					Any			     =    "こんにちは、世界。 \nこんばんは、㔺界。😀"
     UpperCAmelCase_					:					Union[str, Any]			     =    "こんにちは、世界。 \nこんばんは、世界。😀"
     return input_text, output_text







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_     ,   UpperCAmelCase_					:					Tuple			     =    self.get_input_output_texts(lowercase_  )
     UpperCAmelCase_					:					Optional[int]			     =    tokenizer.encode(lowercase_				,   add_special_tokens=lowercase_  )
     UpperCAmelCase_					:					Optional[int]			     =    tokenizer.decode(lowercase_				,   clean_up_tokenization_spaces=lowercase_  )
     return text, ids







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     pass  # TODO add if relevant







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     pass  # TODO add if relevant







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     pass  # TODO add if relevant







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					str			     =    self.get_tokenizer()

     # Testing tokenization
     UpperCAmelCase_					:					Tuple			     =    "こんにちは、世界。　こんばんは、㔺界。"
     UpperCAmelCase_					:					Dict			     =    ["こん", "にちは", "、", "世界", "。", "<SP>", "こん", "ばんは", "、", "㔺界", "。"]
     UpperCAmelCase_					:					int			     =    tokenizer.tokenize(lowercase_  )
     self.assertListEqual(lowercase_				,   lowercase_  )

     # Testing conversion to ids without special tokens
     UpperCAmelCase_					:					int			     =    [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
     UpperCAmelCase_					:					Optional[Any]			     =    tokenizer.convert_tokens_to_ids(lowercase_  )
     self.assertListEqual(lowercase_				,   lowercase_  )

     # Testing conversion to ids with special tokens
     UpperCAmelCase_					:					Tuple			     =    tokens + [tokenizer.unk_token]
     UpperCAmelCase_					:					Optional[int]			     =    [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
     UpperCAmelCase_					:					int			     =    tokenizer.convert_tokens_to_ids(lowercase_  )
     self.assertListEqual(lowercase_				,   lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    self.get_tokenizer()

     # Testing tokenization
     UpperCAmelCase_					:					Optional[int]			     =    "こんにちは、<|bagoftoken|>世界。こんばんは、<|bagoftoken|>㔺界。"
     UpperCAmelCase_					:					Optional[int]			     =    "こんにちは、、、、世界。こんばんは、、、、世界。"
     UpperCAmelCase_					:					Union[str, Any]			     =    tokenizer.encode(lowercase_  )
     UpperCAmelCase_					:					Union[str, Any]			     =    tokenizer.decode(lowercase_  )
     self.assertEqual(lowercase_				,   lowercase_  )







  @slow
  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese"  )

     # Testing tokenization
     UpperCAmelCase_					:					List[Any]			     =    "こんにちは、世界。"
     UpperCAmelCase_					:					List[Any]			     =    "こんばんは、㔺界。😀"
     UpperCAmelCase_					:					List[Any]			     =    "こんにちは、世界。こんばんは、世界。😀"
     UpperCAmelCase_					:					Optional[Any]			     =    tokenizer.encode(prefix_text + input_text  )
     UpperCAmelCase_					:					List[str]			     =    tokenizer.encode(""				,   prefix_text=prefix_text + input_text  )
     UpperCAmelCase_					:					str			     =    tokenizer.encode(lowercase_				,   prefix_text=lowercase_  )
     UpperCAmelCase_					:					List[Any]			     =    tokenizer.decode(lowercase_  )
     UpperCAmelCase_					:					str			     =    tokenizer.decode(lowercase_  )
     UpperCAmelCase_					:					List[str]			     =    tokenizer.decode(lowercase_  )
     self.assertEqual(lowercase_				,   lowercase_  )
     self.assertEqual(lowercase_				,   lowercase_  )
     self.assertEqual(lowercase_				,   lowercase_  )







  @slow
  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Dict			     =    self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese"  )

     # Testing tokenization
     UpperCAmelCase_					:					Union[str, Any]			     =    "こんにちは、世界。"
     UpperCAmelCase_					:					Union[str, Any]			     =    "こんばんは、㔺界。😀"

     UpperCAmelCase_					:					List[Any]			     =    len(tokenizer.encode(lowercase_  )  ) - 2
     UpperCAmelCase_					:					Dict			     =    len(tokenizer.encode(lowercase_  )  ) - 2

     UpperCAmelCase_					:					Union[str, Any]			     =    [1] + [0] * (len_prefix + len_text + 1)
     UpperCAmelCase_					:					Any			     =    [1] * (len_prefix + len_text + 1) + [0]
     UpperCAmelCase_					:					List[Any]			     =    [1] + [1] * (len_prefix) + [0] * (len_text + 1)

     UpperCAmelCase_					:					Dict			     =    tokenizer(prefix_text + input_text  ).token_type_ids
     UpperCAmelCase_					:					Optional[Any]			     =    tokenizer(""				,   prefix_text=prefix_text + input_text  ).token_type_ids
     UpperCAmelCase_					:					str			     =    tokenizer(lowercase_				,   prefix_text=lowercase_  ).token_type_ids
     self.assertListEqual(lowercase_				,   lowercase_  )
     self.assertListEqual(lowercase_				,   lowercase_  )
     self.assertListEqual(lowercase_				,   lowercase_  )







  @slow
  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[str]			     =    self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese"  )

     UpperCAmelCase_					:					str			     =    tokenizer.encode("あンいワ"  )
     UpperCAmelCase_					:					List[Any]			     =    tokenizer.encode(""				,   prefix_text="あンいワ"  )
     UpperCAmelCase_					:					str			     =    tokenizer.encode("いワ"				,   prefix_text="あン"  )

     self.assertEqual(tokenizer.decode(lowercase_  )				,   tokenizer.decode(lowercase_  )  )
     self.assertEqual(tokenizer.decode(lowercase_  )				,   tokenizer.decode(lowercase_  )  )
     self.assertNotEqual(lowercase_				,   lowercase_  )
     self.assertNotEqual(lowercase_				,   lowercase_  )
     self.assertEqual(x_token_a[1]				,   x_token_a[-1]  )  # SEG token
     self.assertEqual(x_token_a[1]				,   x_token_a[3]  )  # SEG token







  @slow
  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Optional[Any]			     =    self.tokenizer_class.from_pretrained("Tanrei/GPTSAN-japanese"  )

     UpperCAmelCase_					:					Tuple			     =    [["武田信玄", "は、"], ["織田信長", "の配下の、"]]
     UpperCAmelCase_					:					Dict			     =    tokenizer(lowercase_				,   padding=lowercase_  )
     UpperCAmelCase_					:					int			     =    tokenizer.batch_encode_plus(lowercase_				,   padding=lowercase_  )

     # fmt: off
     UpperCAmelCase_					:					str			     =    [[3_5993, 8640, 2_5948, 3_5998, 3_0647, 3_5675, 3_5999, 3_5999], [3_5993, 1_0382, 9868, 3_5998, 3_0646, 9459, 3_0646, 3_5675]]
     UpperCAmelCase_					:					Optional[int]			     =    [[1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0]]
     UpperCAmelCase_					:					int			     =    [[1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]]
     # fmt: on
     self.assertListEqual(x_token.input_ids				,   lowercase_  )
     self.assertListEqual(x_token.token_type_ids				,   lowercase_  )
     self.assertListEqual(x_token.attention_mask				,   lowercase_  )
     self.assertListEqual(x_token_a.input_ids				,   lowercase_  )
     self.assertListEqual(x_token_a.token_type_ids				,   lowercase_  )
     self.assertListEqual(x_token_a.attention_mask				,   lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     # Intentionally convert some words to accommodate character fluctuations unique to Japanese
     pass







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     # tokenizer has no padding token
     pass




from scipy.stats import pearsonr

import datasets


_lowerCamelCase					   ="""
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.
The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
"""


_lowerCamelCase					   ="""
Args:
    predictions (`list` of `int`): Predicted class labels, as returned by a model.
    references (`list` of `int`): Ground truth labels.
    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.

Returns:
    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.
    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.

Examples:

    Example 1-A simple example using only predictions and references.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])
        >>> print(round(results['pearsonr'], 2))
        -0.74

    Example 2-The same as Example 1, but that also returns the `p-value`.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)
        >>> print(sorted(list(results.keys())))
        ['p-value', 'pearsonr']
        >>> print(round(results['pearsonr'], 2))
        -0.74
        >>> print(round(results['p-value'], 2))
        0.15
"""


_lowerCamelCase					   ="""
@article{2020SciPy-NMeth,
author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
      Haberland, Matt and Reddy, Tyler and Cournapeau, David and
      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
      Kern, Robert and Larson, Eric and Carey, C J and
      Polat, Ilhan and Feng, Yu and Moore, Eric W. and
      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
      Harris, Charles R. and Archibald, Anne M. and
      Ribeiro, Antonio H. and Pedregosa, Fabian and
      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
      Computing in Python}},
journal = {Nature Methods},
year    = {2020},
volume  = {17},
pages   = {261--272},
adsurl  = {https://rdcu.be/b08Wh},
doi = {10.1038/s41592-019-0686-2},
}
"""





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,   _KWARGS_DESCRIPTION)
class 							A__		(	datasets.Metric):
      def 						UpperCamelCase__							(      self      ):
       return datasets.MetricInfo(
           description=_DESCRIPTION    ,  citation=_CITATION    ,  inputs_description=_KWARGS_DESCRIPTION    ,  features=datasets.Features(
               {
                   """predictions""": datasets.Value("""float"""      ),
                   """references""": datasets.Value("""float"""      ),
               }      )    ,  reference_urls=["""https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html"""]    ,  )






      def 						UpperCamelCase__							(      self    ,  __magic_name__    ,  __magic_name__    ,  __magic_name__=False      ):
       if return_pvalue:
        lowerCamelCase		:	Optional[Any]							=      pearsonr(__magic_name__    ,  __magic_name__      )
        return {"pearsonr": results[0], "p-value": results[1]}
       else:
        return {"pearsonr": float(pearsonr(__magic_name__    ,  __magic_name__      )[0]      )}




