'''simple docstring'''





from __future__ import annotations
def 						__A							(     UpperCAmelCase     ,UpperCAmelCase					)     ->			str:




						'''simple docstring'''
						if b == 0:
												return (1, 0)
						(_UpperCamelCase)			:			List[str]   			=						extended_euclid(UpperCAmelCase     ,a % b					)
						_UpperCamelCase			:			Any   			=						a // b
						return (y, x - k * y)
def 						__A							(     UpperCAmelCase     ,UpperCAmelCase     ,UpperCAmelCase     ,UpperCAmelCase					)     ->			Tuple:




						'''simple docstring'''
						(_UpperCamelCase)			:			Dict   			=						extended_euclid(UpperCAmelCase     ,UpperCAmelCase					)
						_UpperCamelCase			:			List[Any]   			=						na * na
						_UpperCamelCase			:			int   			=						ra * x * na + ra * y * na
						return (n % m + m) % m
def 						__A							(     UpperCAmelCase     ,UpperCAmelCase					)     ->			Any:




						'''simple docstring'''
						(_UpperCamelCase)			:			str   			=						extended_euclid(UpperCAmelCase     ,UpperCAmelCase					)
						if b < 0:
												_UpperCamelCase			:			Union[str, Any]   			=						(b % n + n) % n
						return b
def 						__A							(     UpperCAmelCase     ,UpperCAmelCase     ,UpperCAmelCase     ,UpperCAmelCase					)     ->			List[Any]:




						'''simple docstring'''
						_UpperCamelCase			:			str   			=						invert_modulo(UpperCAmelCase     ,UpperCAmelCase					), invert_modulo(UpperCAmelCase     ,UpperCAmelCase					)
						_UpperCamelCase			:			Any   			=						na * na
						_UpperCamelCase			:			Optional[Any]   			=						ra * x * na + ra * y * na
						return (n % m + m) % m


if __name__ == "__main__":
			from doctest import testmod

			testmod(name="""chinese_remainder_theorem""", verbose=True)
			testmod(name="""chinese_remainder_theorem2""", verbose=True)
			testmod(name="""invert_modulo""", verbose=True)
			testmod(name="""extended_euclid""", verbose=True)



'''simple docstring'''





import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format="""%(asctime)s - %(levelname)s - %(name)s - %(message)s""", datefmt="""%m/%d/%Y %H:%M:%S""", level=logging.INFO
)
lowerCAmelCase_	:		Optional[int]			=     logging.getLogger(__name__)

if __name__ == "__main__":
			lowerCAmelCase_	:		Optional[Any]			=     argparse.ArgumentParser(
			    description="""Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)"""
			)
			parser.add_argument(
			    """--data_file""", type=str, default="""data/dump.bert-base-uncased.pickle""", help="""The binarized dataset."""
			)
			parser.add_argument(
			    """--token_counts_dump""", type=str, default="""data/token_counts.bert-base-uncased.pickle""", help="""The dump file."""
			)
			parser.add_argument("""--vocab_size""", default=3_0522, type=int)
			lowerCAmelCase_	:		str			=     parser.parse_args()

			logger.info(f"""Loading data from {args.data_file}""")
			with open(args.data_file, """rb""") as fp:
						lowerCAmelCase_	:		Tuple			=     pickle.load(fp)

			logger.info("""Counting occurrences for MLM.""")
			lowerCAmelCase_	:		str			=     Counter()
			for tk_ids in data:
						counter.update(tk_ids)
			lowerCAmelCase_	:		Any			=     [0] * args.vocab_size
			for k, v in counter.items():
						lowerCAmelCase_	:		Optional[Any]			=     v

			logger.info(f"""Dump to {args.token_counts_dump}""")
			with open(args.token_counts_dump, """wb""") as handle:
						pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)


