class_docstr: Register as an `DataCollator` with name `LanguageModelingDataCollator`
  Used for language modeling.
class_docstr_tok: ["Register","as","an","`","DataCollator","`","with","name","`","LanguageModelingDataCollator","`","Used","for","language","modeling","."]
code: def __init__(
      self,
      model_name: str,
      mlm: bool = True,
      mlm_probability: float = 0.15,
      filed_name: str = "source",
      namespace: str = "tokens",
  ):
      self._field_name = filed_name
      self._namespace = namespace
      from allennlp.common import cached_transformers
  
      tokenizer = cached_transformers.get_tokenizer(model_name)
      self._collator = DataCollatorForLanguageModeling(
          tokenizer, mlm, mlm_probability
      )
      if hasattr(self._collator, "mask_tokens"):
          # For compatibility with transformers < 4.10
          self._mask_tokens = self._collator.mask_tokens
      else:
          self._mask_tokens = self._collator.torch_mask_tokens
  
file_path: allennlp/allennlp/data/data_loaders/data_collator.py
imports: from typing import List
  from transformers.data.data_collator import DataCollatorForLanguageModeling
  from allennlp.common import Registrable
  from allennlp.data.batch import Batch
  from allennlp.data.data_loaders.data_loader import TensorDict
  from allennlp.data.instance import Instance
label_desc: Use image node_id 1 to create a new LanguageModelingDataCollator object from inherited base classes: DataCollator with example: obj = LanguageModelingDataCollator(model_name, mlm, mlm_probability, filed_name, namespace)