




# Usage:
# ./gen-card-facebook-wmt19.py

import os
from pathlib import Path



def 				_A  (		lowerCAmelCase_	:   str  ,							lowerCAmelCase_	:   Dict  ,							lowerCAmelCase_	:   int     ):
     """simple docstring"""

     lowerCAmelCase__            =					{
         "en": "Machine learning is great, isn't it?",
         "ru": "Машинное обучение - это здорово, не так ли?",
         "de": "Maschinelles Lernen ist großartig, oder?",
     }

     # BLUE scores as follows:
     # "pair": [fairseq, transformers]
     lowerCAmelCase__            =					{
         "ru-en": ["[41.3](http://matrix.statmt.org/matrix/output/1907?run_id=6937)", "39.20"],
         "en-ru": ["[36.4](http://matrix.statmt.org/matrix/output/1914?run_id=6724)", "33.47"],
         "en-de": ["[43.1](http://matrix.statmt.org/matrix/output/1909?run_id=6862)", "42.83"],
         "de-en": ["[42.3](http://matrix.statmt.org/matrix/output/1902?run_id=6750)", "41.35"],
     }
     lowerCAmelCase__            =					F'{src_lang}-{tgt_lang}'

     lowerCAmelCase__            =					F'\n---\nlanguage: \n- {src_lang}\n- {tgt_lang}\nthumbnail:\ntags:\n- translation\n- wmt19\n- facebook\nlicense: apache-2.0\ndatasets:\n- wmt19\nmetrics:\n- bleu\n---\n\n# FSMT\n\n## Model description\n\nThis is a ported version of [fairseq wmt19 transformer](https://github.com/pytorch/fairseq/blob/master/examples/wmt19/README.md) for {src_lang}-{tgt_lang}.\n\nFor more details, please see, [Facebook FAIR\'s WMT19 News Translation Task Submission](https://arxiv.org/abs/1907.06616).\n\nThe abbreviation FSMT stands for FairSeqMachineTranslation\n\nAll four models are available:\n\n* [wmt19-en-ru](https://huggingface.co/facebook/wmt19-en-ru)\n* [wmt19-ru-en](https://huggingface.co/facebook/wmt19-ru-en)\n* [wmt19-en-de](https://huggingface.co/facebook/wmt19-en-de)\n* [wmt19-de-en](https://huggingface.co/facebook/wmt19-de-en)\n\n## Intended uses & limitations\n\n#### How to use\n\n```python\nfrom transformers import FSMTForConditionalGeneration, FSMTTokenizer\nmname = "facebook/wmt19-{src_lang}-{tgt_lang}"\ntokenizer = FSMTTokenizer.from_pretrained(mname)\nmodel = FSMTForConditionalGeneration.from_pretrained(mname)\n\ninput = "{texts[src_lang]}"\ninput_ids = tokenizer.encode(input, return_tensors="pt")\noutputs = model.generate(input_ids)\ndecoded = tokenizer.decode(outputs[0], skip_special_tokens=True)\nprint(decoded) # {texts[tgt_lang]}\n\n```\n\n#### Limitations and bias\n\n- The original (and this ported model) doesn\'t seem to handle well inputs with repeated sub-phrases, [content gets truncated](https://discuss.huggingface.co/t/issues-with-translating-inputs-containing-repeated-phrases/981)\n\n## Training data\n\nPretrained weights were left identical to the original model released by fairseq. For more details, please, see the [paper](https://arxiv.org/abs/1907.06616).\n\n## Eval results\n\npair   | fairseq | transformers\n-------|---------|----------\n{pair}  | {scores[pair][0]} | {scores[pair][1]}\n\nThe score is slightly below the score reported by `fairseq`, since `transformers`` currently doesn\'t support:\n- model ensemble, therefore the best performing checkpoint was ported (``model4.pt``).\n- re-ranking\n\nThe score was calculated using this code:\n\n```bash\ngit clone https://github.com/huggingface/transformers\ncd transformers\nexport PAIR={pair}\nexport DATA_DIR=data/$PAIR\nexport SAVE_DIR=data/$PAIR\nexport BS=8\nexport NUM_BEAMS=15\nmkdir -p $DATA_DIR\nsacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source\nsacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target\necho $PAIR\nPYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS\n```\nnote: fairseq reports using a beam of 50, so you should get a slightly higher score if re-run with `--num_beams 50`.\n\n## Data Sources\n\n- [training, etc.](http://www.statmt.org/wmt19/)\n- [test set](http://matrix.statmt.org/test_sets/newstest2019.tgz?1556572561)\n\n\n### BibTeX entry and citation info\n\n```bibtex\n@inproceedings{{...,\n  year={{2020}},\n  title={{Facebook FAIR\'s WMT19 News Translation Task Submission}},\n  author={{Ng, Nathan and Yee, Kyra and Baevski, Alexei and Ott, Myle and Auli, Michael and Edunov, Sergey}},\n  booktitle={{Proc. of WMT}},\n}}\n```\n\n\n## TODO\n\n- port model ensemble (fairseq uses 4 model checkpoints)\n\n'
     os.makedirs(lowerCAmelCase_  ,							exist_ok=lowerCAmelCase_     )
     lowerCAmelCase__            =					os.path.join(lowerCAmelCase_  ,							"README.md"     )
     print(F'Generating {path}'     )
     with open(lowerCAmelCase_  ,							"w"  ,							encoding="utf-8"     ) as f:
          f.write(lowerCAmelCase_     )


# make sure we are under the root of the project
UpperCamelCase								=	Path(__file__).resolve().parent.parent.parent
UpperCamelCase								=	repo_dir / 'model_cards'

for model_name in ["wmt19-ru-en", "wmt19-en-ru", "wmt19-en-de", "wmt19-de-en"]:
     UpperCamelCase		,    UpperCamelCase		,    UpperCamelCase								=	model_name.split('-')
     UpperCamelCase								=	model_cards_dir / 'facebook' / model_name
     write_model_card(model_card_dir, src_lang=src_lang, tgt_lang=tgt_lang)

import os
import pickle
import unittest

from transformers import AutoTokenizer
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.models.bert_japanese.tokenization_bert_japanese import (
    VOCAB_FILES_NAMES,
    BertJapaneseTokenizer,
    CharacterTokenizer,
    JumanppTokenizer,
    MecabTokenizer,
    SudachiTokenizer,
    WordpieceTokenizer,
)
from transformers.testing_utils import custom_tokenizers, require_jumanpp, require_sudachi

from ...test_tokenization_common import TokenizerTesterMixin

@custom_tokenizers
class 					_lowercase    (     UpperCAmelCase__ ,  unittest.TestCase			):






    '''simple docstring'''
    SCREAMING_SNAKE_CASE:				Union[str, Any]          =    BertJapaneseTokenizer
    SCREAMING_SNAKE_CASE:				Dict          =    False
    SCREAMING_SNAKE_CASE:				List[Any]          =    True




    def      _a    (    self ):
       super().setUp()

       lowerCAmelCase_:							Any       =	[
           "[UNK]",
           "[CLS]",
           "[SEP]",
           "こんにちは",
           "こん",
           "にちは",
           "ばんは",
           "##こん",
           "##にちは",
           "##ばんは",
           "世界",
           "##世界",
           "、",
           "##、",
           "。",
           "##。",
       ]

       lowerCAmelCase_:							Optional[Any]       =	os.path.join(self.tmpdirname       ,						VOCAB_FILES_NAMES["vocab_file"] )
       with open(self.vocab_file       ,						"w"       ,						encoding="utf-8" ) as vocab_writer:
          vocab_writer.write("".join([x + "\n" for x in vocab_tokens] ) )




    def      _a    (    self       ,						lowerCamelCase__ ):
       lowerCAmelCase_:							Optional[int]       =	"こんにちは、世界。 \nこんばんは、世界。"
       lowerCAmelCase_:							Optional[int]       =	"こんにちは 、 世界 。 こんばんは 、 世界 。"
       return input_text, output_text




    def      _a    (    self       ,						lowerCamelCase__ ):
       lowerCAmelCase_  ,	lowerCAmelCase_:							str       =	self.get_input_output_texts(lowerCamelCase__ )
       lowerCAmelCase_:							Dict       =	tokenizer.encode(lowerCamelCase__       ,						add_special_tokens=lowerCamelCase__ )
       lowerCAmelCase_:							List[str]       =	tokenizer.decode(lowerCamelCase__       ,						clean_up_tokenization_spaces=lowerCamelCase__ )
       return text, ids




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       lowerCAmelCase_:							Union[str, Any]       =	self.tokenizer_class(self.vocab_file )

       lowerCAmelCase_:							Any       =	tokenizer.tokenize("こんにちは、世界。\nこんばんは、世界。" )
       self.assertListEqual(lowerCamelCase__       ,						["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"] )
       self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__ )       ,						[3, 12, 10, 14, 4, 9, 12, 10, 14] )




    def      _a    (    self ):
       lowerCAmelCase_:							List[Any]       =	self.tokenizer_class(self.vocab_file       ,						word_tokenizer_type="mecab" )
       self.assertIsNotNone(lowerCamelCase__ )

       lowerCAmelCase_:							str       =	"こんにちは、世界。\nこんばんは、世界。"
       lowerCAmelCase_:							List[Any]       =	tokenizer.tokenize(lowerCamelCase__ )
       self.assertListEqual(lowerCamelCase__       ,						["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"] )
       self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__ )       ,						[3, 12, 10, 14, 4, 9, 12, 10, 14] )

       lowerCAmelCase_:							Dict       =	os.path.join(self.tmpdirname       ,						"tokenizer.bin" )
       with open(lowerCamelCase__       ,						"wb" ) as handle:
          pickle.dump(lowerCamelCase__       ,						lowerCamelCase__ )

       with open(lowerCamelCase__       ,						"rb" ) as handle:
          lowerCAmelCase_:							Union[str, Any]       =	pickle.load(lowerCamelCase__ )

       lowerCAmelCase_:							Union[str, Any]       =	tokenizer_new.tokenize(lowerCamelCase__ )

       self.assertListEqual(lowerCamelCase__       ,						lowerCamelCase__ )




    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	MecabTokenizer(mecab_dic="ipadic" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップルストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]       ,						)




    def      _a    (    self ):
       try:
          lowerCAmelCase_:							List[Any]       =	MecabTokenizer(mecab_dic="unidic_lite" )
       except ModuleNotFoundError:
          return

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]       ,						)




    def      _a    (    self ):
       try:
          lowerCAmelCase_:							str       =	MecabTokenizer(mecab_dic="unidic" )
       except ModuleNotFoundError:
          return

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]       ,						)




    def      _a    (    self ):
       lowerCAmelCase_:							List[Any]       =	MecabTokenizer(do_lower_case=lowerCamelCase__       ,						mecab_dic="ipadic" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップルストア", "で", "iphone", "8", "が", "発売", "さ", "れ", "た", "。"]       ,						)




    def      _a    (    self ):
       try:
          lowerCAmelCase_:							Any       =	MecabTokenizer(
              do_lower_case=lowerCamelCase__       ,						normalize_text=lowerCamelCase__       ,						mecab_option="-d /usr/local/lib/mecab/dic/jumandic" )
       except RuntimeError:
          # if dict doesn't exist in the system, previous code raises this error.
          return

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れた", "\u3000", "。"]       ,						)




    def      _a    (    self ):
       lowerCAmelCase_:							str       =	MecabTokenizer(normalize_text=lowerCamelCase__       ,						mecab_dic="ipadic" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れ", "た", "　", "。"]       ,						)




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Any       =	self.tokenizer_class(self.vocab_file       ,						word_tokenizer_type="sudachi" )
       self.assertIsNotNone(lowerCamelCase__ )

       lowerCAmelCase_:							str       =	"こんにちは、世界。\nこんばんは、世界。"
       lowerCAmelCase_:							List[str]       =	tokenizer.tokenize(lowerCamelCase__ )
       self.assertListEqual(lowerCamelCase__       ,						["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"] )
       self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__ )       ,						[3, 12, 10, 14, 4, 9, 12, 10, 14] )

       lowerCAmelCase_:							Optional[int]       =	os.path.join(self.tmpdirname       ,						"tokenizer.bin" )
       with open(lowerCamelCase__       ,						"wb" ) as handle:
          pickle.dump(lowerCamelCase__       ,						lowerCamelCase__ )

       with open(lowerCamelCase__       ,						"rb" ) as handle:
          lowerCAmelCase_:							List[str]       =	pickle.load(lowerCamelCase__ )

       lowerCAmelCase_:							Optional[int]       =	tokenizer_new.tokenize(lowerCamelCase__ )

       self.assertListEqual(lowerCamelCase__       ,						lowerCamelCase__ )




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Union[str, Any]       =	SudachiTokenizer(sudachi_dict_type="core" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						[" ", "\t", "アップル", "ストア", "で", "iPhone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]       ,						)




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Optional[int]       =	SudachiTokenizer(sudachi_dict_type="core"       ,						sudachi_split_mode="A" )

       self.assertListEqual(tokenizer.tokenize("外国人参政権" )       ,						["外国", "人", "参政", "権"] )




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Any       =	SudachiTokenizer(sudachi_dict_type="core"       ,						sudachi_split_mode="B" )

       self.assertListEqual(tokenizer.tokenize("外国人参政権" )       ,						["外国人", "参政権"] )




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Dict       =	SudachiTokenizer(sudachi_dict_type="core"       ,						sudachi_split_mode="C" )

       self.assertListEqual(tokenizer.tokenize("外国人参政権" )       ,						["外国人参政権"] )




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	SudachiTokenizer(do_lower_case=lowerCamelCase__       ,						sudachi_dict_type="core" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						[" ", "\t", "アップル", "ストア", "で", "iphone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]       ,						)




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Union[str, Any]       =	SudachiTokenizer(normalize_text=lowerCamelCase__       ,						sudachi_dict_type="core" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						[" ", "\t", "ｱｯﾌﾟﾙ", "ストア", "で", "iPhone", "８", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", "\u3000", "。", " ", " "]       ,						)




    @require_sudachi
    def      _a    (    self ):
       lowerCAmelCase_:							Tuple       =	SudachiTokenizer(trim_whitespace=lowerCamelCase__       ,						sudachi_dict_type="core" )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]       ,						)




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							int       =	self.tokenizer_class(self.vocab_file       ,						word_tokenizer_type="jumanpp" )
       self.assertIsNotNone(lowerCamelCase__ )

       lowerCAmelCase_:							Any       =	"こんにちは、世界。\nこんばんは、世界。"
       lowerCAmelCase_:							Optional[int]       =	tokenizer.tokenize(lowerCamelCase__ )
       self.assertListEqual(lowerCamelCase__       ,						["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"] )
       self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__ )       ,						[3, 12, 10, 14, 4, 9, 12, 10, 14] )

       lowerCAmelCase_:							Optional[Any]       =	os.path.join(self.tmpdirname       ,						"tokenizer.bin" )
       with open(lowerCamelCase__       ,						"wb" ) as handle:
          pickle.dump(lowerCamelCase__       ,						lowerCamelCase__ )

       with open(lowerCamelCase__       ,						"rb" ) as handle:
          lowerCAmelCase_:							Any       =	pickle.load(lowerCamelCase__ )

       lowerCAmelCase_:							Union[str, Any]       =	tokenizer_new.tokenize(lowerCamelCase__ )

       self.assertListEqual(lowerCamelCase__       ,						lowerCamelCase__ )




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							Union[str, Any]       =	JumanppTokenizer()

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iPhone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]       ,						)




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	JumanppTokenizer(do_lower_case=lowerCamelCase__ )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iphone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]       ,						)




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							Optional[Any]       =	JumanppTokenizer(normalize_text=lowerCamelCase__ )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["ｱ", "ｯ", "ﾌ", "ﾟ", "ﾙ", "ストア", "で", "iPhone", "８", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]       ,						)




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	JumanppTokenizer(trim_whitespace=lowerCamelCase__ )

       self.assertListEqual(
           tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  " )       ,						["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れた", "。"]       ,						)




    @require_jumanpp
    def      _a    (    self ):
       lowerCAmelCase_:							Any       =	JumanppTokenizer()

       self.assertListEqual(
           tokenizer.tokenize("ありがとうございますm(_ _)ｍ見つけるのが大変です。" )       ,						["ありがとう", "ございます", "m(_ _)m", "見つける", "の", "が", "大変です", "。"]       ,						)




    def      _a    (    self ):
       lowerCAmelCase_:							Optional[int]       =	["[UNK]", "[CLS]", "[SEP]", "こんにちは", "こん", "にちは", "ばんは", "##こん", "##にちは", "##ばんは"]

       lowerCAmelCase_:							Tuple       =	{}
       for i, token in enumerate(lowerCamelCase__ ):
          lowerCAmelCase_:							List[Any]       =	i
       lowerCAmelCase_:							List[str]       =	WordpieceTokenizer(vocab=lowerCamelCase__       ,						unk_token="[UNK]" )

       self.assertListEqual(tokenizer.tokenize("" )       ,						[] )

       self.assertListEqual(tokenizer.tokenize("こんにちは" )       ,						["こんにちは"] )

       self.assertListEqual(tokenizer.tokenize("こんばんは" )       ,						["こん", "##ばんは"] )

       self.assertListEqual(tokenizer.tokenize("こんばんは こんばんにちは こんにちは" )       ,						["こん", "##ばんは", "[UNK]", "こんにちは"] )




    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	BertJapaneseTokenizer.from_pretrained("nlp-waseda/roberta-base-japanese-with-auto-jumanpp" )
       lowerCAmelCase_:							Optional[Any]       =	tokenizer.subword_tokenizer

       lowerCAmelCase_:							List[str]       =	subword_tokenizer.tokenize("国境 の 長い トンネル を 抜ける と 雪国 であった 。" )
       self.assertListEqual(lowerCamelCase__       ,						["▁国境", "▁の", "▁長い", "▁トンネル", "▁を", "▁抜ける", "▁と", "▁雪", "国", "▁であった", "▁。"] )

       lowerCAmelCase_:							Optional[int]       =	subword_tokenizer.tokenize("こんばんは こんばん にち は こんにちは" )
       self.assertListEqual(lowerCamelCase__       ,						["▁こん", "ばん", "は", "▁こん", "ばん", "▁に", "ち", "▁は", "▁こんにちは"] )




    def      _a    (    self ):
       lowerCAmelCase_:							str       =	self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese" )

       lowerCAmelCase_:							int       =	tokenizer.encode("ありがとう。"       ,						add_special_tokens=lowerCamelCase__ )
       lowerCAmelCase_:							Optional[int]       =	tokenizer.encode("どういたしまして。"       ,						add_special_tokens=lowerCamelCase__ )

       lowerCAmelCase_:							List[Any]       =	tokenizer.build_inputs_with_special_tokens(lowerCamelCase__ )
       lowerCAmelCase_:							List[Any]       =	tokenizer.build_inputs_with_special_tokens(lowerCamelCase__       ,						lowerCamelCase__ )

       # 2 is for "[CLS]", 3 is for "[SEP]"
       assert encoded_sentence == [2] + text + [3]
       assert encoded_pair == [2] + text + [3] + text_a + [3]





@custom_tokenizers
class 					_lowercase    (     UpperCAmelCase__ ,  unittest.TestCase			):






    '''simple docstring'''
    SCREAMING_SNAKE_CASE:				Tuple          =    BertJapaneseTokenizer
    SCREAMING_SNAKE_CASE:				Optional[Any]          =    False




    def      _a    (    self ):
       super().setUp()

       lowerCAmelCase_:							Any       =	["[UNK]", "[CLS]", "[SEP]", "こ", "ん", "に", "ち", "は", "ば", "世", "界", "、", "。"]

       lowerCAmelCase_:							int       =	os.path.join(self.tmpdirname       ,						VOCAB_FILES_NAMES["vocab_file"] )
       with open(self.vocab_file       ,						"w"       ,						encoding="utf-8" ) as vocab_writer:
          vocab_writer.write("".join([x + "\n" for x in vocab_tokens] ) )




    def      _a    (    self       ,						**lowerCamelCase__ ):
       return BertJapaneseTokenizer.from_pretrained(self.tmpdirname       ,						subword_tokenizer_type="character"       ,						**lowerCamelCase__ )




    def      _a    (    self       ,						lowerCamelCase__ ):
       lowerCAmelCase_:							str       =	"こんにちは、世界。 \nこんばんは、世界。"
       lowerCAmelCase_:							Tuple       =	"こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。"
       return input_text, output_text




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       pass  # TODO add if relevant




    def      _a    (    self ):
       lowerCAmelCase_:							str       =	self.tokenizer_class(self.vocab_file       ,						subword_tokenizer_type="character" )

       lowerCAmelCase_:							Any       =	tokenizer.tokenize("こんにちは、世界。 \nこんばんは、世界。" )
       self.assertListEqual(
           lowerCamelCase__       ,						["こ", "ん", "に", "ち", "は", "、", "世", "界", "。", "こ", "ん", "ば", "ん", "は", "、", "世", "界", "。"] )
       self.assertListEqual(
           tokenizer.convert_tokens_to_ids(lowerCamelCase__ )       ,						[3, 4, 5, 6, 7, 11, 9, 10, 12, 3, 4, 8, 4, 7, 11, 9, 10, 12] )




    def      _a    (    self ):
       lowerCAmelCase_:							Optional[Any]       =	["[UNK]", "[CLS]", "[SEP]", "こ", "ん", "に", "ち", "は", "ば", "世", "界", "、", "。"]

       lowerCAmelCase_:							List[str]       =	{}
       for i, token in enumerate(lowerCamelCase__ ):
          lowerCAmelCase_:							Optional[Any]       =	i
       lowerCAmelCase_:							List[Any]       =	CharacterTokenizer(vocab=lowerCamelCase__       ,						unk_token="[UNK]" )

       self.assertListEqual(tokenizer.tokenize("" )       ,						[] )

       self.assertListEqual(tokenizer.tokenize("こんにちは" )       ,						["こ", "ん", "に", "ち", "は"] )

       self.assertListEqual(tokenizer.tokenize("こんにちほ" )       ,						["こ", "ん", "に", "ち", "[UNK]"] )




    def      _a    (    self ):
       lowerCAmelCase_:							Optional[Any]       =	self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese-char" )

       lowerCAmelCase_:							Any       =	tokenizer.encode("ありがとう。"       ,						add_special_tokens=lowerCamelCase__ )
       lowerCAmelCase_:							Dict       =	tokenizer.encode("どういたしまして。"       ,						add_special_tokens=lowerCamelCase__ )

       lowerCAmelCase_:							Dict       =	tokenizer.build_inputs_with_special_tokens(lowerCamelCase__ )
       lowerCAmelCase_:							Any       =	tokenizer.build_inputs_with_special_tokens(lowerCamelCase__       ,						lowerCamelCase__ )

       # 2 is for "[CLS]", 3 is for "[SEP]"
       assert encoded_sentence == [2] + text + [3]
       assert encoded_pair == [2] + text + [3] + text_a + [3]





@custom_tokenizers
class 					_lowercase    (     unittest.TestCase			):






    '''simple docstring'''




    def      _a    (    self ):
       lowerCAmelCase_:							Union[str, Any]       =	"cl-tohoku/bert-base-japanese"
       lowerCAmelCase_:							Optional[int]       =	AutoTokenizer.from_pretrained(lowerCamelCase__ )
       self.assertIsInstance(lowerCamelCase__       ,						lowerCamelCase__ )





class 					_lowercase    (     unittest.TestCase			):






    '''simple docstring'''




    def      _a    (    self ):
       lowerCAmelCase_:							Dict       =	"cl-tohoku/bert-base-japanese"
       with self.assertLogs("transformers"       ,						level="WARNING" ) as cm:
          BertTokenizer.from_pretrained(lowerCamelCase__ )
          self.assertTrue(
              cm.records[0].message.startswith(
                  "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                  " is called from." ) )
       lowerCAmelCase_:							List[str]       =	"bert-base-cased"
       with self.assertLogs("transformers"       ,						level="WARNING" ) as cm:
          BertJapaneseTokenizer.from_pretrained(lowerCamelCase__ )
          self.assertTrue(
              cm.records[0].message.startswith(
                  "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                  " is called from." ) )