"""simple docstring"""






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

import sentencepiece as spm

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


lowerCAmelCase__  :  Union[str, Any]						     =	logging.get_logger(__name__)

lowerCAmelCase__  :  List[str]						     =	'▁'

lowerCAmelCase__  :  Union[str, Any]						     =	{'vocab_file': 'sentencepiece.bpe.model'}

lowerCAmelCase__  :  Tuple						     =	{
    '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'
        ),
    }
}

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

# fmt: off
lowerCAmelCase__  :  List[Any]						     =	['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 				snake_case       ( __lowerCamelCase				):




					"""simple docstring"""

					snake_case__				    = VOCAB_FILES_NAMES
					snake_case__				    = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					snake_case__				    = PRETRAINED_VOCAB_FILES_MAP
					snake_case__				    = ["input_ids", "attention_mask"]

					snake_case__				    = []
					snake_case__				    = []







					def __init__(				self   :	Tuple    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Tuple="<s>"    ,lowerCamelCase__   :	Any="</s>"    ,lowerCamelCase__   :	Dict="</s>"    ,lowerCamelCase__   :	List[str]="<s>"    ,lowerCamelCase__   :	Union[str, Any]="<unk>"    ,lowerCamelCase__   :	str="<pad>"    ,lowerCamelCase__   :	Optional[Any]="<mask>"    ,lowerCamelCase__   :	Any=None    ,lowerCamelCase__   :	int=None    ,lowerCamelCase__   :	Optional[int]=None    ,lowerCamelCase__   :	Dict = None    ,lowerCamelCase__   :	int=None    ,**lowerCamelCase__   :	str    ,):
									UpperCAmelCase__             =							AddedToken(lowerCamelCase__    ,lstrip=lowerCamelCase__    ,rstrip=lowerCamelCase__			) if isinstance(lowerCamelCase__    ,lowerCamelCase__			) else mask_token

									UpperCAmelCase__             =							{} if sp_model_kwargs is None else sp_model_kwargs

									super().__init__(
									    bos_token=lowerCamelCase__    ,eos_token=lowerCamelCase__    ,unk_token=lowerCamelCase__    ,sep_token=lowerCamelCase__    ,cls_token=lowerCamelCase__    ,pad_token=lowerCamelCase__    ,mask_token=lowerCamelCase__    ,tokenizer_file=lowerCamelCase__    ,src_lang=lowerCamelCase__    ,tgt_lang=lowerCamelCase__    ,additional_special_tokens=lowerCamelCase__    ,sp_model_kwargs=self.sp_model_kwargs    ,**lowerCamelCase__    ,)

									UpperCAmelCase__             =							spm.SentencePieceProcessor(**self.sp_model_kwargs			)
									self.sp_model.Load(str(lowerCamelCase__			)			)
									UpperCAmelCase__             =							vocab_file

									# Original fairseq vocab and spm vocab must be "aligned":
									# Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
									# -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
									# fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
									# spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

									# Mimic fairseq token-to-id alignment for the first 4 token
									UpperCAmelCase__             =							{'''<s>''': 0, '''<pad>''': 1, '''</s>''': 2, '''<unk>''': 3}

									# The first "real" token "," has position 4 in the original fairseq vocab and position 3 in the spm vocab
									UpperCAmelCase__             =							1

									UpperCAmelCase__             =							len(self.sp_model			)
									UpperCAmelCase__             =							{
									    code: self.sp_model_size + i + self.fairseq_offset for i, code in enumerate(lowerCamelCase__			)
									}
									UpperCAmelCase__             =							{v: k for k, v in self.lang_code_to_id.items()}
									UpperCAmelCase__             =							len(self.sp_model			) + len(self.lang_code_to_id			) + self.fairseq_offset

									self.fairseq_tokens_to_ids.update(self.lang_code_to_id			)
									UpperCAmelCase__             =							{v: k for k, v in self.fairseq_tokens_to_ids.items()}
									UpperCAmelCase__             =							list(self.lang_code_to_id.keys()			)

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

									UpperCAmelCase__             =							src_lang if src_lang is not None else '''en_XX'''
									UpperCAmelCase__             =							self.lang_code_to_id[self._src_lang]
									UpperCAmelCase__             =							tgt_lang
									self.set_src_lang_special_tokens(self._src_lang			)







					def __getstate__(				self   :	Any			):
									UpperCAmelCase__             =							self.__dict__.copy()
									UpperCAmelCase__             =							None
									UpperCAmelCase__             =							self.sp_model.serialized_model_proto()
									return state







					def __setstate__(				self   :	Optional[int]    ,lowerCamelCase__   :	Dict			):
									UpperCAmelCase__             =							d

									# for backward compatibility
									if not hasattr(self    ,'sp_model_kwargs'			):
													UpperCAmelCase__             =							{}

									UpperCAmelCase__             =							spm.SentencePieceProcessor(**self.sp_model_kwargs			)
									self.sp_model.LoadFromSerializedProto(self.sp_model_proto			)







					@property
					def 		__lowerCAmelCase						(				self   :	Optional[Any]			):
									return len(self.sp_model			) + len(self.lang_code_to_id			) + self.fairseq_offset + 1  # Plus 1 for the mask token







					@property
					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									return self._src_lang







					@src_lang.setter
					def 		__lowerCAmelCase						(				self   :	Optional[int]    ,lowerCamelCase__   :	int			):
									UpperCAmelCase__             =							new_src_lang
									self.set_src_lang_special_tokens(self._src_lang			)







					def 		__lowerCAmelCase						(				self   :	List[str]    ,lowerCamelCase__   :	str    ,lowerCamelCase__   :	Optional[int] = None    ,lowerCamelCase__   :	int = False			):

									if already_has_special_tokens:
													return super().get_special_tokens_mask(
													    token_ids_a=lowerCamelCase__    ,token_ids_a=lowerCamelCase__    ,already_has_special_tokens=lowerCamelCase__			)

									UpperCAmelCase__             =							[1] * len(self.prefix_tokens			)
									UpperCAmelCase__             =							[1] * len(self.suffix_tokens			)
									if token_ids_a is None:
													return prefix_ones + ([0] * len(lowerCamelCase__			)) + suffix_ones
									return prefix_ones + ([0] * len(lowerCamelCase__			)) + ([0] * len(lowerCamelCase__			)) + suffix_ones







					def 		__lowerCAmelCase						(				self   :	List[Any]    ,lowerCamelCase__   :	Optional[int]    ,lowerCamelCase__   :	List[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   :	List[Any]    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Optional[int] = None			):
									UpperCAmelCase__             =							[self.sep_token_id]
									UpperCAmelCase__             =							[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   :	Dict    ,lowerCamelCase__   :	Union[str, Any]    ,lowerCamelCase__   :	Any    ,lowerCamelCase__   :	Tuple    ,lowerCamelCase__   :	int    ,**lowerCamelCase__   :	int			):
									if src_lang is None or tgt_lang is None:
													raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'			)
									UpperCAmelCase__             =							src_lang
									UpperCAmelCase__             =							self(lowerCamelCase__    ,add_special_tokens=lowerCamelCase__    ,return_tensors=lowerCamelCase__    ,**lowerCamelCase__			)
									UpperCAmelCase__             =							self.convert_tokens_to_ids(lowerCamelCase__			)
									UpperCAmelCase__             =							tgt_lang_id
									return inputs







					def 		__lowerCAmelCase						(				self   :	int			):
									UpperCAmelCase__             =							{self.convert_ids_to_tokens(lowerCamelCase__			): i for i in range(self.vocab_size			)}
									vocab.update(self.added_tokens_encoder			)
									return vocab







					def 		__lowerCAmelCase						(				self   :	Union[str, Any]    ,lowerCamelCase__   :	Any			):
									return self.sp_model.encode(lowerCamelCase__    ,out_type=lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Dict    ,lowerCamelCase__   :	Union[str, Any]			):
									if token in self.fairseq_tokens_to_ids:
													return self.fairseq_tokens_to_ids[token]
									UpperCAmelCase__             =							self.sp_model.PieceToId(lowerCamelCase__			)

									# Need to return unknown token if the SP model returned 0
									return spm_id + self.fairseq_offset if spm_id else self.unk_token_id







					def 		__lowerCAmelCase						(				self   :	List[str]    ,lowerCamelCase__   :	Any			):
									if index in self.fairseq_ids_to_tokens:
													return self.fairseq_ids_to_tokens[index]
									return self.sp_model.IdToPiece(index - self.fairseq_offset			)







					def 		__lowerCAmelCase						(				self   :	str    ,lowerCamelCase__   :	Any			):
									UpperCAmelCase__             =							''''''.join(lowerCamelCase__			).replace(lowerCamelCase__    ,' '			).strip()
									return out_string







					def 		__lowerCAmelCase						(				self   :	Optional[Any]    ,lowerCamelCase__   :	List[Any]    ,lowerCamelCase__   :	List[str] = None			):
									if not os.path.isdir(lowerCamelCase__			):
													logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''			)
													return
									UpperCAmelCase__             =							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__			) and os.path.isfile(self.vocab_file			):
													copyfile(self.vocab_file    ,lowerCamelCase__			)
									elif not os.path.isfile(self.vocab_file			):
													with open(lowerCamelCase__    ,'wb'			) as fi:
																	UpperCAmelCase__             =							self.sp_model.serialized_model_proto()
																	fi.write(lowerCamelCase__			)

									return (out_vocab_file,)







					def 		__lowerCAmelCase						(				self   :	Tuple    ,lowerCamelCase__   :	Union[str, Any]    ,lowerCamelCase__   :	List[str] = "en_XX"    ,lowerCamelCase__   :	Dict = None    ,lowerCamelCase__   :	Dict = "ro_RO"    ,**lowerCamelCase__   :	Dict    ,):
									UpperCAmelCase__             =							src_lang
									UpperCAmelCase__             =							tgt_lang
									return super().prepare_seqaseq_batch(lowerCamelCase__    ,lowerCamelCase__    ,**lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									return self.set_src_lang_special_tokens(self.src_lang			)







					def 		__lowerCAmelCase						(				self   :	int			):
									return self.set_tgt_lang_special_tokens(self.tgt_lang			)







					def 		__lowerCAmelCase						(				self   :	List[Any]    ,lowerCamelCase__   :	Optional[int]			):
									UpperCAmelCase__             =							self.lang_code_to_id[src_lang]
									UpperCAmelCase__             =							[]
									UpperCAmelCase__             =							[self.eos_token_id, self.cur_lang_code]







					def 		__lowerCAmelCase						(				self   :	Tuple    ,lowerCamelCase__   :	Union[str, Any]			):
									UpperCAmelCase__             =							self.lang_code_to_id[lang]
									UpperCAmelCase__             =							[]
									UpperCAmelCase__             =							[self.eos_token_id, self.cur_lang_code]










import logging
import os
from dataclasses import dataclass, field
from typing import Dict, Optional

import datasets
import numpy as np
import tensorflow as tf

from transformers import (
    AutoConfig,
    AutoTokenizer,
    EvalPrediction,
    HfArgumentParser,
    PreTrainedTokenizer,
    TFAutoModelForSequenceClassification,
    TFTrainer,
    TFTrainingArguments,
)
from transformers.utils import logging as hf_logging


hf_logging.set_verbosity_info()
hf_logging.enable_default_handler()
hf_logging.enable_explicit_format()




def 		lowerCAmelCase_    (  __UpperCAmelCase:			str		,   __UpperCAmelCase:			str		,   __UpperCAmelCase:			str		,   __UpperCAmelCase:			PreTrainedTokenizer		,   __UpperCAmelCase:			int		,   __UpperCAmelCase:			Optional[int] = None		,   )      ->	List[Any]:
    UpperCamelCase__							:				Dict          =      {}

    if train_file is not None:
        UpperCamelCase__							:				str          =      [train_file]
    if eval_file is not None:
        UpperCamelCase__							:				Union[str, Any]          =      [eval_file]
    if test_file is not None:
        UpperCamelCase__							:				Tuple          =      [test_file]

    UpperCamelCase__							:				Optional[Any]          =      datasets.load_dataset('''csv'''		,   data_files=__UpperCAmelCase      )
    UpperCamelCase__							:				List[Any]          =      list(ds[list(files.keys()      )[0]].features.keys()      )
    UpperCamelCase__							:				str          =      features_name.pop(__UpperCAmelCase      )
    UpperCamelCase__							:				List[str]          =      list(set(ds[list(files.keys()      )[0]][label_name]      )      )
    UpperCamelCase__							:				Optional[Any]          =      {label: i for i, label in enumerate(__UpperCAmelCase      )}
    UpperCamelCase__							:				Union[str, Any]          =      tokenizer.model_input_names
    UpperCamelCase__							:				str          =      {}

    if len(__UpperCAmelCase      ) == 1:
        for k in files.keys():
            UpperCamelCase__							:				Optional[int]          =      ds[k].map(
                lambda __UpperCAmelCase      : tokenizer.batch_encode_plus(
                    example[features_name[0]]		,   truncation=__UpperCAmelCase		,   max_length=__UpperCAmelCase		,   padding='''max_length'''      )		,   batched=__UpperCAmelCase		,   )
    elif len(__UpperCAmelCase      ) == 2:
        for k in files.keys():
            UpperCamelCase__							:				Dict          =      ds[k].map(
                lambda __UpperCAmelCase      : tokenizer.batch_encode_plus(
                    (example[features_name[0]], example[features_name[1]])		,   truncation=__UpperCAmelCase		,   max_length=__UpperCAmelCase		,   padding='''max_length'''		,   )		,   batched=__UpperCAmelCase		,   )

    def gen_train():
        for ex in transformed_ds[datasets.Split.TRAIN]:
            UpperCamelCase__							:				Any          =      {k: v for k, v in ex.items() if k in input_names}
            UpperCamelCase__							:				str          =      labelaid[ex[label_name]]
            yield (d, label)

    def gen_val():
        for ex in transformed_ds[datasets.Split.VALIDATION]:
            UpperCamelCase__							:				Union[str, Any]          =      {k: v for k, v in ex.items() if k in input_names}
            UpperCamelCase__							:				str          =      labelaid[ex[label_name]]
            yield (d, label)

    def gen_test():
        for ex in transformed_ds[datasets.Split.TEST]:
            UpperCamelCase__							:				Optional[Any]          =      {k: v for k, v in ex.items() if k in input_names}
            UpperCamelCase__							:				int          =      labelaid[ex[label_name]]
            yield (d, label)

    UpperCamelCase__							:				Tuple          =      (
        tf.data.Dataset.from_generator(
            __UpperCAmelCase		,   ({k: tf.intaa for k in input_names}, tf.intaa)		,   ({k: tf.TensorShape([None]      ) for k in input_names}, tf.TensorShape([]      ))		,   )
        if datasets.Split.TRAIN in transformed_ds
        else None
    )

    if train_ds is not None:
        UpperCamelCase__							:				Optional[Any]          =      train_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.TRAIN]      )      )      )

    UpperCamelCase__							:				int          =      (
        tf.data.Dataset.from_generator(
            __UpperCAmelCase		,   ({k: tf.intaa for k in input_names}, tf.intaa)		,   ({k: tf.TensorShape([None]      ) for k in input_names}, tf.TensorShape([]      ))		,   )
        if datasets.Split.VALIDATION in transformed_ds
        else None
    )

    if val_ds is not None:
        UpperCamelCase__							:				Dict          =      val_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.VALIDATION]      )      )      )

    UpperCamelCase__							:				Optional[Any]          =      (
        tf.data.Dataset.from_generator(
            __UpperCAmelCase		,   ({k: tf.intaa for k in input_names}, tf.intaa)		,   ({k: tf.TensorShape([None]      ) for k in input_names}, tf.TensorShape([]      ))		,   )
        if datasets.Split.TEST in transformed_ds
        else None
    )

    if test_ds is not None:
        UpperCamelCase__							:				Union[str, Any]          =      test_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.TEST]      )      )      )

    return train_ds, val_ds, test_ds, labelaid


UpperCAmelCase_     							= logging.getLogger(__name__)






@dataclass
class     lowercase__       :

   '''simple docstring'''


   a						:							int   		=		field(metadata={"help": "Which column contains the label"}				)
   a						:							str   		=		field(default=__lowerCamelCase			,				metadata={"help": "The path of the training file"}				)
   a						:							Optional[str]   		=		field(default=__lowerCamelCase			,				metadata={"help": "The path of the development file"}				)
   a						:							Optional[str]   		=		field(default=__lowerCamelCase			,				metadata={"help": "The path of the test file"}				)
   a						:							int   		=		field(
       default=128			,				metadata={
           "help": (
               "The maximum total input sequence length after tokenization. Sequences longer "
               "than this will be truncated, sequences shorter will be padded."
           )
       }			,				)
   a						:							bool   		=		field(
       default=__lowerCamelCase			,				metadata={"help": "Overwrite the cached training and evaluation sets"}				)






@dataclass
class     lowercase__       :

   '''simple docstring'''


   a						:							str   		=		field(
       metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}				)
   a						:							Optional[str]   		=		field(
       default=__lowerCamelCase			,				metadata={"help": "Pretrained config name or path if not the same as model_name"}				)
   a						:							Optional[str]   		=		field(
       default=__lowerCamelCase			,				metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"}				)
   a						:							bool   		=		field(default=__lowerCamelCase			,				metadata={"help": "Set this flag to use fast tokenization."}				)
   # If you want to tweak more attributes on your tokenizer, you should do it in a distinct script,
   # or just modify its tokenizer_config.json.
   a						:							Optional[str]   		=		field(
       default=__lowerCamelCase			,				metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"}			,				)




def 		lowerCAmelCase_    (  )      ->	int:
    # See all possible arguments in src/transformers/training_args.py
    # or by passing the --help flag to this script.
    # We now keep distinct sets of args, for a cleaner separation of concerns.
    UpperCamelCase__							:				Tuple          =      HfArgumentParser((ModelArguments, DataTrainingArguments, TFTrainingArguments)      )
    UpperCamelCase__   ,UpperCamelCase__   ,UpperCamelCase__							:				Any          =      parser.parse_args_into_dataclasses()

    if (
        os.path.exists(training_args.output_dir      )
        and os.listdir(training_args.output_dir      )
        and training_args.do_train
        and not training_args.overwrite_output_dir
    ):
        raise ValueError(
            f"Output directory ({training_args.output_dir}) already exists and is not empty. Use"
            ''' --overwrite_output_dir to overcome.'''      )

    # Setup logging
    logging.basicConfig(
        format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s'''		,   datefmt='''%m/%d/%Y %H:%M:%S'''		,   level=logging.INFO		,   )
    logger.info(
        f"n_replicas: {training_args.n_replicas}, distributed training: {bool(training_args.n_replicas > 1      )}, "
        f"16-bits training: {training_args.fpaa}"      )
    logger.info(f"Training/evaluation parameters {training_args}"      )

    # Load pretrained model and tokenizer
    #
    # Distributed training:
    # The .from_pretrained methods guarantee that only one local process can concurrently
    # download model & vocab.

    UpperCamelCase__							:				List[str]          =      AutoTokenizer.from_pretrained(
        model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path		,   cache_dir=model_args.cache_dir		,   )

    UpperCamelCase__   ,UpperCamelCase__   ,UpperCamelCase__   ,UpperCamelCase__							:				Optional[int]          =      get_tfds(
        train_file=data_args.train_file		,   eval_file=data_args.dev_file		,   test_file=data_args.test_file		,   tokenizer=__UpperCAmelCase		,   label_column_id=data_args.label_column_id		,   max_seq_length=data_args.max_seq_length		,   )

    UpperCamelCase__							:				int          =      AutoConfig.from_pretrained(
        model_args.config_name if model_args.config_name else model_args.model_name_or_path		,   num_labels=len(__UpperCAmelCase      )		,   labelaid=__UpperCAmelCase		,   idalabel={id: label for label, id in labelaid.items()}		,   finetuning_task='''text-classification'''		,   cache_dir=model_args.cache_dir		,   )

    with training_args.strategy.scope():
        UpperCamelCase__							:				str          =      TFAutoModelForSequenceClassification.from_pretrained(
            model_args.model_name_or_path		,   from_pt=bool('''.bin''' in model_args.model_name_or_path      )		,   config=__UpperCAmelCase		,   cache_dir=model_args.cache_dir		,   )

    def compute_metrics(__UpperCAmelCase:			EvalPrediction      ) -> Dict:
        UpperCamelCase__							:				Optional[Any]          =      np.argmax(p.predictions		,   axis=1      )

        return {"acc": (preds == p.label_ids).mean()}

    # Initialize our Trainer
    UpperCamelCase__							:				Union[str, Any]          =      TFTrainer(
        model=__UpperCAmelCase		,   args=__UpperCAmelCase		,   train_dataset=__UpperCAmelCase		,   eval_dataset=__UpperCAmelCase		,   compute_metrics=__UpperCAmelCase		,   )

    # Training
    if training_args.do_train:
        trainer.train()
        trainer.save_model()
        tokenizer.save_pretrained(training_args.output_dir      )

    # Evaluation
    UpperCamelCase__							:				List[str]          =      {}
    if training_args.do_eval:
        logger.info('''*** Evaluate ***'''      )
        UpperCamelCase__							:				Tuple          =      trainer.evaluate()
        UpperCamelCase__							:				Optional[int]          =      os.path.join(training_args.output_dir		,   '''eval_results.txt'''      )

        with open(__UpperCAmelCase		,   '''w'''      ) as writer:
            logger.info('''***** Eval results *****'''      )

            for key, value in result.items():
                logger.info(f"  {key} = {value}"      )
                writer.write(f"{key} = {value}\n"      )

            results.update(__UpperCAmelCase      )

    return results


if __name__ == "__main__":
  main()

