code: def csv_tok_text_gen_mlm(
      tokenizer: PreTrainedTokenizer,
      dataset: Dataset,
      args: Union[GENTrainArgs, WPTrainArgs, GENEvalArgs, WPEvalArgs],
      mlm=True,
  ) -> Dataset:
      if args.max_length is None:
          max_input_length = tokenizer.model_max_length
      else:
          max_input_length = args.max_length
  
      def tokenize_function(example):
          texts = example["text"]
          toks = tokenizer(
              texts,
              padding="max_length",
              truncation=True,
              max_length=max_input_length,
          )
          if not mlm:
              toks["labels"] = toks["input_ids"]
          return toks
  
      dataset = dataset.map(
          tokenize_function, batched=True, remove_columns=["text"]
      )
  
      return dataset
  
file_path: happy-transformer/happytransformer/fine_tuning_util.py
imports: from dataclasses import dataclass
  from typing import Union
  from datasets import Dataset
  from transformers import PreTrainedTokenizer, TrainerCallback
  from happytransformer.args import GENTrainArgs, WPTrainArgs, GENEvalArgs, WPEvalArgs
label_desc: Use image node_id 2 for calling a global function with example usage: csv_tok_text_gen_mlm(tokenizer, dataset, args, mlm) and returns: dataset, toks