class_docstr: ALBEF pretrain model.
  
  Supported model types:
      - base: ALBEF base model used for pretraining.
docstr: Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original.
docstr_tok: ["Prepare","masked","tokens","inputs\/labels","for","masked","language","modeling",":","80","%","MASK",",","10","%","random",",","10","%","original","."]
code: def mask(
      self,
      input_ids,
      vocab_size,
      device,
      targets=None,
      masked_indices=None,
      probability_matrix=None,
  ):
      """
      Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original.
      """
      if masked_indices is None:
          masked_indices = torch.bernoulli(probability_matrix).bool()
  
      masked_indices[input_ids == self.tokenizer.pad_token_id] = False
      masked_indices[input_ids == self.tokenizer.cls_token_id] = False
  
      if targets is not None:
          targets[
              ~masked_indices
          ] = -100  # We only compute loss on masked tokens
  
      # 80% of the time, we replace masked input tokens with tokenizer.mask_token ([MASK])
      indices_replaced = (
          torch.bernoulli(torch.full(input_ids.shape, 0.8)).bool()
          & masked_indices
      )
      input_ids[indices_replaced] = self.tokenizer.mask_token_id
  
      # 10% of the time, we replace masked input tokens with random word
      indices_random = (
          torch.bernoulli(torch.full(input_ids.shape, 0.5)).bool()
          & masked_indices
          & ~indices_replaced
      )
      random_words = torch.randint(
          vocab_size, input_ids.shape, dtype=torch.long
      ).to(device)
      input_ids[indices_random] = random_words[indices_random]
      # The rest of the time (10% of the time) we keep the masked input tokens unchanged
  
      if targets is not None:
          return input_ids, targets
      else:
          return input_ids
  
imports: from copy import deepcopy
  import numpy
  import torch
  import torch.nn.functional
  from lavis.common.registry import registry
  from lavis.common.utils import get_abs_path
  from lavis.models.albef_models import AlbefBase
  from lavis.models.albef_models.albef_outputs import AlbefIntermediateOutput, AlbefOutput, AlbefSimilarity
  from lavis.models.base_model import MomentumDistilationMixin, SharedQueueMixin
  from lavis.models.med import BertForMaskedLM
  from lavis.models.vit import VisionTransformerEncoder
  from torch import nn
  from transformers import BertConfig
label_desc: Use image node_id 4 for calling the AlbefPretrain obj's underlying member method code with example usage: obj.mask(input_ids, vocab_size, device, targets, masked_indices, probability_matrix) and returns: input_ids,  targets, input_ids