

"""simple docstring"""





import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import ClassLabel, Features, Value
from .base import TaskTemplate







@dataclass(frozen=UpperCAmelCase__       )
class 				SCREAMING_SNAKE_CASE					(		UpperCAmelCase__       ):






					"""simple docstring"""



					lowercase__				 =       field(default="text-classification"    ,							metadata={"include_in_asdict_even_if_is_default": True}       )
					lowercase__				 =       Features({"text": Value("string"       )}       )
					lowercase__				 =       Features({"labels": ClassLabel}       )
					lowercase__				 =       "text"
					lowercase__				 =       "labels"







					def        __lowerCAmelCase (       self			:				Union[str, Any]   ,lowercase_			:				Optional[Any]		):


						if self.label_column not in features:
							raise ValueError(F'Column {self.label_column} is not present in features.'		)
						if not isinstance(features[self.label_column]   ,lowercase_		):
							raise ValueError(F'Column {self.label_column} is not a ClassLabel.'		)
						lowerCAmelCase__	:						str  				=	copy.deepcopy(self		)
						lowerCAmelCase__	:						Tuple  				=	self.label_schema.copy()
						lowerCAmelCase__	:						Any  				=	features[self.label_column]
						lowerCAmelCase__	:						Any  				=	label_schema
						return task_template







					@property
					def        __lowerCAmelCase (       self			:				str		):
						return {
						    self.text_column: "text",
						    self.label_column: "labels",
						}












"""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
)
UpperCAmelCase_   : Dict   			= logging.getLogger(__name__)

if __name__ == "__main__":
  UpperCAmelCase_   : List[str]   			= 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=30522, type=int)
  UpperCAmelCase_   : Optional[Any]   			= parser.parse_args()

  logger.info(f'''Loading data from {args.data_file}''')
  with open(args.data_file, """rb""") as fp:
    UpperCAmelCase_   : Union[str, Any]   			= pickle.load(fp)

  logger.info("""Counting occurrences for MLM.""")
  UpperCAmelCase_   : Any   			= Counter()
  for tk_ids in data:
    counter.update(tk_ids)
  UpperCAmelCase_   : List[Any]   			= [0] * args.vocab_size
  for k, v in counter.items():
    UpperCAmelCase_   : Dict   			= 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)


