class_docstr: Left-to-right Transformer language model.
docstr: Lightning calls this inside the training loop with the data from the training dataloader
  passed in as `batch`.
docstr_tok: ["Lightning","calls","this","inside","the","training","loop","with","the","data","from","the","training","dataloader","passed","in","as","`","batch","`","."]
code: def training_step(self, batch, batch_idx):
      """
      Lightning calls this inside the training loop with the data from the training dataloader
      passed in as `batch`.
      """
      # forward pass
      for i in range(len(batch)):
          if batch[i].ndim == 3:
              # Dataset returns already batched data and the first dimension of size 1
              # added by DataLoader is excess.
              batch[i] = batch[i].squeeze(dim=0)
      ids, mask = batch
      input_ids, labels = ids[:, :-1], ids[:, 1:]
      input_mask = mask[:, :-1]
      log_probs = self(input_ids=input_ids, attention_mask=input_mask)
  
      train_loss = self.loss_fn(log_probs=log_probs, labels=labels)
  
      tensorboard_logs = {
          "train_loss": train_loss,
          "lr": self._optimizer.param_groups[0]["lr"],
      }
      return {"loss": train_loss, "log": tensorboard_logs}
  
imports: import json
  import math
  from typing import Dict, Optional
  import numpy
  import torch
  import torch.utils.data
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import SmoothedCrossEntropyLoss
  from nemo.collections.common.metrics import GlobalAverageLossMetric
  from nemo.collections.common.parts import transformer_weights_init
  from nemo.collections.nlp.data import SentenceDataset, TarredSentenceDataset
  from nemo.collections.nlp.metrics import SequencePerplexity
  from nemo.collections.nlp.modules.common import TokenClassifier
  from nemo.collections.nlp.modules.common.lm_utils import get_transformer
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.core.classes.common import typecheck
  from nemo.core.classes.modelPT import ModelPT
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 3 for calling the TransformerLMModel obj's underlying member method code with example usage: obj.training_step(batch, batch_idx) and returns: dict