class_docstr: This is the current default pretext task module.
  
  Functionality:
  
      self.get:
          inputs: (data, target) (target will often be None)
          outputs: (pretext_data, pretext_target)
  
          called before the forward pass through the TabTransformer to create the
          input and label for a BERT-style pretext task.
  
      self.forward:
          inputs: out (embedding for TabTransformer), target (pretext task label)
          outputs: loss, % accuracy on pretext task
  
          given the embedding it passes it through a classifier which learns to
          predict the pretext label.
code: def get(self, data, target):
      cat_feats = data
  
      orig_cat_feats = deepcopy(cat_feats.detach())
  
      if self.replacement_noise == "swap":
          n_cat = cat_feats.shape[1]
          cols_to_shuffle = np.random.choice(
              n_cat, int(self.p_replace * n_cat), replace=False
          )
          for col in cols_to_shuffle:
              cat_feats[:, col] = cat_feats[:, col][
                  torch.randperm(cat_feats.shape[0])
              ]
  
      elif self.replacement_noise == "random":
          locs_to_replace = (
              torch.empty_like(cat_feats, dtype=float).uniform_()
              < self.p_replace
          )
          col_cardinalities = torch.LongTensor(
              [i[1] for i in self.cat_feat_origin_cards]
          ).to(cat_feats)
          col_cardinalities = col_cardinalities.unsqueeze(0).expand_as(
              cat_feats
          )
  
          unif = torch.rand(
              cat_feats.shape, device=col_cardinalities.device
          )
          random_feats = (unif * col_cardinalities).floor().to(
              torch.int64
          ) + 1  # + 1 since 0 is the padding value
  
          extra_replace = torch.mul(
              (cat_feats == random_feats).to(int),
              locs_to_replace.to(int),
          ).to(torch.bool)
          cat_feats[locs_to_replace] = random_feats[locs_to_replace]
  
          assert (
              torch.all(
                  cat_feats[extra_replace]
                  == orig_cat_feats[extra_replace]
              ).item()
              is True
          )
          extra_plus1 = cat_feats[extra_replace] + 1
          extra_minus1 = cat_feats[extra_replace] - 1
          extra_zero_padd_idx = extra_minus1 == 0
          extra_minus1[extra_zero_padd_idx] = extra_plus1[
              extra_zero_padd_idx
          ]
  
          cat_feats[extra_replace] = extra_minus1
          assert (
              torch.all(
                  ~(
                      cat_feats[extra_replace]
                      == orig_cat_feats[extra_replace]
                  )
              ).item()
              is True
          )
  
      elif self.replacement_noise == "low_rank":
          assert (
              self.p_replace + 0.2 <= 1
          ), "p_replace too big, lower it!"
          weights = torch.tensor(
              [self.p_replace, 0.1, 0.9 - self.p_replace],
              dtype=torch.float,
          )  # 0=pad, 1=replace with random value, 2=dont change
  
          locs_to_change = torch.multinomial(
              weights, np.prod(cat_feats.shape), replacement=True
          ).view(cat_feats.shape)
          col_cardinalities = torch.LongTensor(
              [i[1] for i in self.cat_feat_origin_cards]
          ).to(cat_feats)
          col_cardinalities = col_cardinalities.unsqueeze(0).expand_as(
              cat_feats
          )
  
          unif = torch.rand(
              cat_feats.shape, device=col_cardinalities.device
          )
          random_feats = (unif * col_cardinalities).floor().to(
              torch.int64
          ) + 1  # + 1 since 0 is the padding value
  
          extra_replace = torch.mul(
              (cat_feats == random_feats).to(int),
              (locs_to_change == 1).to(int),
          ).to(torch.bool)
          cat_feats[locs_to_change == 1] = random_feats[
              locs_to_change == 1
          ]
          cat_feats[locs_to_change == 0] = 0
  
          assert (
              torch.all(
                  cat_feats[extra_replace]
                  == orig_cat_feats[extra_replace]
              ).item()
              is True
          )
          extra_plus1 = cat_feats[extra_replace] + 1
          extra_minus1 = cat_feats[extra_replace] - 1
          extra_zero_padd_idx = extra_minus1 == 0
          extra_minus1[extra_zero_padd_idx] = extra_plus1[
              extra_zero_padd_idx
          ]
  
          cat_feats[extra_replace] = extra_minus1
          assert (
              torch.all(
                  ~(
                      cat_feats[extra_replace]
                      == orig_cat_feats[extra_replace]
                  )
              ).item()
              is True
          )
  
      pretext_label = (cat_feats != orig_cat_feats).long()
      pretext_data = cat_feats
  
      pretext_data = pretext_data.to(self.device, non_blocking=True)
      pretext_label = pretext_label.to(self.device, non_blocking=True)
  
      return pretext_data, pretext_label
  
file_path: autogluon/tabular/src/autogluon/tabular/models/tab_transformer/pretexts.py
imports: from copy import deepcopy
  import numpy
  import torch
  import torch.nn
  from autogluon.core.constants import REGRESSION
label_desc: Use image node_id 3 for calling the BERTPretext obj's underlying member method code with example usage: obj.get(data, target) and returns: pretext_data,  pretext_label