




"""simple docstring"""

import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
       from .tokenization_mbart import MBartTokenizer
else:
       a         =      None


a         =      logging.get_logger(__name__)


a         =      {'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

a         =      {
    '''vocab_file''': {
        '''facebook/mbart-large-en-ro''': (
            '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model'''
        ),
        '''facebook/mbart-large-cc25''': (
            '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/mbart-large-en-ro''': '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json''',
        '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json''',
    },
}

a         =      {
    '''facebook/mbart-large-en-ro''': 1_024,
    '''facebook/mbart-large-cc25''': 1_024,
}

# fmt: off
a         =      ['''ar_AR''', '''cs_CZ''', '''de_DE''', '''en_XX''', '''es_XX''', '''et_EE''', '''fi_FI''', '''fr_XX''', '''gu_IN''', '''hi_IN''', '''it_IT''', '''ja_XX''', '''kk_KZ''', '''ko_KR''', '''lt_LT''', '''lv_LV''', '''my_MM''', '''ne_NP''', '''nl_XX''', '''ro_RO''', '''ru_RU''', '''si_LK''', '''tr_TR''', '''vi_VN''', '''zh_CN''']



class     lowercase_	(					a__							):



 '''simple docstring'''
 UpperCAmelCase   :					Union[str, Any]				  =     VOCAB_FILES_NAMES
 UpperCAmelCase   :					Union[str, Any]				  =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 UpperCAmelCase   :					Any				  =     PRETRAINED_VOCAB_FILES_MAP
 UpperCAmelCase   :					Any				  =     ['input_ids', 'attention_mask']
 UpperCAmelCase   :					Tuple				  =     MBartTokenizer

 UpperCAmelCase   :					List[int]				  =     []
 UpperCAmelCase   :					List[int]				  =     []

 def __init__(			self	:	Tuple   ,							_UpperCAmelCase	:	Tuple=None   ,							_UpperCAmelCase	:	str=None   ,							_UpperCAmelCase	:	List[str]="<s>"   ,							_UpperCAmelCase	:	Dict="</s>"   ,							_UpperCAmelCase	:	str="</s>"   ,							_UpperCAmelCase	:	List[str]="<s>"   ,							_UpperCAmelCase	:	int="<unk>"   ,							_UpperCAmelCase	:	Union[str, Any]="<pad>"   ,							_UpperCAmelCase	:	Dict="<mask>"   ,							_UpperCAmelCase	:	Any=None   ,							_UpperCAmelCase	:	Any=None   ,							_UpperCAmelCase	:	Optional[Any]=None   ,							**_UpperCAmelCase	:	List[Any]   ,							):
       # Mask token behave like a normal word, i.e. include the space before it
       _A        =       AddedToken(_lowerCamelCase   ,							lstrip=_lowerCamelCase   ,							rstrip=_lowerCamelCase		) if isinstance(_lowerCamelCase   ,							_lowerCamelCase		) else mask_token

       super().__init__(
           vocab_file=_lowerCamelCase   ,							tokenizer_file=_lowerCamelCase   ,							bos_token=_lowerCamelCase   ,							eos_token=_lowerCamelCase   ,							sep_token=_lowerCamelCase   ,							cls_token=_lowerCamelCase   ,							unk_token=_lowerCamelCase   ,							pad_token=_lowerCamelCase   ,							mask_token=_lowerCamelCase   ,							src_lang=_lowerCamelCase   ,							tgt_lang=_lowerCamelCase   ,							additional_special_tokens=_lowerCamelCase   ,							**_lowerCamelCase   ,							)

       _A        =       vocab_file
       _A        =       False if not self.vocab_file else True

       _A        =       FAIRSEQ_LANGUAGE_CODES.copy()

       if additional_special_tokens is not None:
             # Only add those special tokens if they are not already there.
             _additional_special_tokens.extend(
                 [t for t in additional_special_tokens if t not in _additional_special_tokens]		)

       self.add_special_tokens({'additional_special_tokens': _additional_special_tokens}		)
       _A        =       {
           lang_code: self.convert_tokens_to_ids(_lowerCamelCase		) for lang_code in FAIRSEQ_LANGUAGE_CODES
       }

       _A        =       src_lang if src_lang is not None else '''en_XX'''
       _A        =       self.convert_tokens_to_ids(self._src_lang		)
       _A        =       tgt_lang
       self.set_src_lang_special_tokens(self._src_lang		)

 @property
 def       lowerCAmelCase_							(			self	:	int		):
       return self._src_lang

 @src_lang.setter
 def       lowerCAmelCase_							(			self	:	int   ,							_UpperCAmelCase	:	Optional[int]		):
       _A        =       new_src_lang
       self.set_src_lang_special_tokens(self._src_lang		)

 def       lowerCAmelCase_							(			self	:	Optional[int]   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	str = None		):
       if token_ids_a is None:
             return self.prefix_tokens + token_ids_a + self.suffix_tokens
       # We don't expect to process pairs, but leave the pair logic for API consistency
       return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens

 def       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	Tuple = None		):
       _A        =       [self.sep_token_id]
       _A        =       [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]

 def       lowerCAmelCase_							(			self	:	Optional[Any]   ,							_UpperCAmelCase	:	Union[str, Any]   ,							_UpperCAmelCase	:	Any   ,							_UpperCAmelCase	:	Optional[int]   ,							_UpperCAmelCase	:	List[Any]   ,							**_UpperCAmelCase	:	Any		):
       if src_lang is None or tgt_lang is None:
             raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'		)
       _A        =       src_lang
       _A        =       self(_lowerCamelCase   ,							add_special_tokens=_lowerCamelCase   ,							return_tensors=_lowerCamelCase   ,							**_lowerCamelCase		)
       _A        =       self.convert_tokens_to_ids(_lowerCamelCase		)
       _A        =       tgt_lang_id
       return inputs

 def       lowerCAmelCase_							(			self	:	Optional[Any]   ,							_UpperCAmelCase	:	Tuple   ,							_UpperCAmelCase	:	List[Any] = "en_XX"   ,							_UpperCAmelCase	:	Optional[int] = None   ,							_UpperCAmelCase	:	int = "ro_RO"   ,							**_UpperCAmelCase	:	List[str]   ,							):
       _A        =       src_lang
       _A        =       tgt_lang
       return super().prepare_seqaseq_batch(_lowerCamelCase   ,							_lowerCamelCase   ,							**_lowerCamelCase		)

 def       lowerCAmelCase_							(			self	:	List[str]		):
       return self.set_src_lang_special_tokens(self.src_lang		)

 def       lowerCAmelCase_							(			self	:	Optional[int]		):
       return self.set_tgt_lang_special_tokens(self.tgt_lang		)

 def       lowerCAmelCase_							(			self	:	List[str]   ,							_UpperCAmelCase	:	int		):
       _A        =       self.convert_tokens_to_ids(_lowerCamelCase		)
       _A        =       []
       _A        =       [self.eos_token_id, self.cur_lang_code]

       _A        =       self.convert_ids_to_tokens(self.prefix_tokens		)
       _A        =       self.convert_ids_to_tokens(self.suffix_tokens		)

       _A        =       processors.TemplateProcessing(
           single=prefix_tokens_str + ['$A'] + suffix_tokens_str   ,							pair=prefix_tokens_str + ['$A', '$B'] + suffix_tokens_str   ,							special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,							self.prefix_tokens + self.suffix_tokens		)		)   ,							)

 def       lowerCAmelCase_							(			self	:	Optional[int]   ,							_UpperCAmelCase	:	Any		):
       _A        =       self.convert_tokens_to_ids(_lowerCamelCase		)
       _A        =       []
       _A        =       [self.eos_token_id, self.cur_lang_code]

       _A        =       self.convert_ids_to_tokens(self.prefix_tokens		)
       _A        =       self.convert_ids_to_tokens(self.suffix_tokens		)

       _A        =       processors.TemplateProcessing(
           single=prefix_tokens_str + ['$A'] + suffix_tokens_str   ,							pair=prefix_tokens_str + ['$A', '$B'] + suffix_tokens_str   ,							special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,							self.prefix_tokens + self.suffix_tokens		)		)   ,							)



 def       lowerCAmelCase_							(			self	:	Dict   ,							_UpperCAmelCase	:	Dict   ,							_UpperCAmelCase	:	Optional[int] = None		):
       if not self.can_save_slow_tokenizer:
             raise ValueError(
                 'Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '
                 'tokenizer.'		)

       if not os.path.isdir(_lowerCamelCase		):
             logger.error(F'''Vocabulary path ({save_directory}) should be a directory.'''		)
             return
       _A        =       os.path.join(
           _lowerCamelCase   ,							(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']		)

       if os.path.abspath(self.vocab_file		) != os.path.abspath(_lowerCamelCase		):
             copyfile(self.vocab_file   ,							_lowerCamelCase		)

       return (out_vocab_file,)







"""simple docstring"""

import logging
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, Union

from .generation.configuration_utils import GenerationConfig
from .training_args import TrainingArguments
from .utils import add_start_docstrings


a         =      logging.getLogger(__name__)





@dataclass
@add_start_docstrings(TrainingArguments.__doc__							)
class     lowercase_	(					__lowerCAmelCase							):



 '''simple docstring'''
 UpperCAmelCase   :					bool				  =     field(default=__lowerCAmelCase      ,     metadata={'''help''': '''Whether to use SortishSampler or not.'''}							)
 UpperCAmelCase   :					bool				  =     field(
     default=__lowerCAmelCase      ,     metadata={'''help''': '''Whether to use generate to calculate generative metrics (ROUGE, BLEU).'''}							)
 UpperCAmelCase   :					Optional[int]				  =     field(
     default=__lowerCAmelCase      ,     metadata={
         '''help''': (
             '''The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
             '''to the `max_length` value of the model configuration.'''
         )
     }      ,     )
 UpperCAmelCase   :					Optional[int]				  =     field(
     default=__lowerCAmelCase      ,     metadata={
         '''help''': (
             '''The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
             '''to the `num_beams` value of the model configuration.'''
         )
     }      ,     )
 UpperCAmelCase   :					Optional[Union[str, Path, GenerationConfig]]				  =     field(
     default=__lowerCAmelCase      ,     metadata={
         '''help''': '''Model id, file path or url pointing to a GenerationConfig json file, to use during prediction.'''
     }      ,     )

 def       lowerCAmelCase_							(			self	:	int		):
       _A        =       super().to_dict()
       for k, v in d.items():
             if isinstance(_UpperCAmelCase   ,							_UpperCAmelCase		):
                   _A        =       v.to_dict()
       return d

