class_docstr: <a id="NLPClassificationConfigs"></a>
  
  ## Trainer configurations
  
  This has the basic configurations for NLP classification task training.
  All the properties are configurable.
class_docstr_tok: ["<","a","id=","''","NLPClassificationConfigs","''",">","<","\/a",">","#","#","Trainer","configurations","This","has","the","basic","configurations","for","NLP","classification","task","training",".","All","the","properties","are","configurable","."]
docstr: ### Training or validation step
docstr_tok: ["#","#","#","Training","or","validation","step"]
code: def step(self, batch: any, batch_idx: BatchIndex):
      """
      ### Training or validation step
      """
  
      # Move data to the device
      data, target = batch[0].to(self.device), batch[1].to(self.device)
  
      # Update global step (number of tokens processed) when in training mode
      if self.mode.is_train:
          tracker.add_global_step(data.shape[1])
  
      # Whether to capture model outputs
      with self.mode.update(
          is_log_activations=batch_idx.is_last
          and self.is_log_model_activations
      ):
          # Get model outputs.
          # It's returning a tuple for states when using RNNs.
          # This is not implemented yet. 😜
          output, *_ = self.model(data)
  
      # Calculate and log loss
      loss = self.loss_func(output, target)
      tracker.add("loss.", loss)
  
      # Calculate and log accuracy
      self.accuracy(output, target)
      self.accuracy.track()
  
      # Train the model
      if self.mode.is_train:
          # Calculate gradients
          loss.backward()
          # Clip gradients
          torch.nn.utils.clip_grad_norm_(
              self.model.parameters(), max_norm=self.grad_norm_clip
          )
          # Take optimizer step
          self.optimizer.step()
          # Log the model parameters and gradients on last batch of every epoch
          if batch_idx.is_last and self.is_log_model_params_grads:
              tracker.add("model", self.model)
          # Clear the gradients
          self.optimizer.zero_grad()
  
      # Save the tracked metrics
      tracker.save()
  
imports: from collections import Counter
  from typing import Callable
  import torch
  import torchtext
  from torch import nn
  from torch.utils.data import DataLoader
  import torchtext.vocab
  from torchtext.vocab import Vocab
  from labml import lab, tracker, monit
  from labml.configs import option
  from labml_helpers.device import DeviceConfigs
  from labml_helpers.metrics.accuracy import Accuracy
  from labml_helpers.module import Module
  from labml_helpers.train_valid import TrainValidConfigs, hook_model_outputs, BatchIndex
  from labml_nn.optimizers.configs import OptimizerConfigs
label_desc: Use image node_id 2 for calling the NLPClassificationConfigs obj's underlying member method code with example usage: obj.step(batch, batch_idx) without return types