code: def create_embedding(
      self, best_label, sm, module_selector, tensors, text
  ):
      batch_len = text.size(0)
      sm_t = torch.t(sm)
  
      reduction_tmp = self.criterion.reduction
      self.criterion.reduction = "none"
  
      modules = dict(
          {name: module for name, module in self.model.named_modules()}
      )
      grad = module_selector(modules).weight.grad
      grad_size = grad.flatten().size(0)
  
      arr = torch.empty(batch_len, grad_size * self.num_classes)
      for c in range(self.num_classes):
          loss = self.criterion(
              sm, torch.LongTensor([c] * batch_len).to(self.device)
          )
  
          for k in range(batch_len):
              self.model.zero_grad()
              loss[k].backward(retain_graph=True)
  
              modules = dict(
                  {
                      name: module
                      for name, module in self.model.named_modules()
                  }
              )
              params = module_selector(modules).weight.grad.flatten()
  
              with torch.no_grad():
                  sm_prob = sm_t[c][k]
                  if c == best_label[k]:
                      arr[k, grad_size * c : grad_size * (c + 1)] = (
                          1 - sm_prob
                      ) * params
                  else:
                      arr[k, grad_size * c : grad_size * (c + 1)] = (
                          -1 * sm_prob * params
                      )
  
      tensors.extend(arr.detach().to("cpu", non_blocking=True).numpy())
      self.criterion.reduction = reduction_tmp
  
      return batch_len
  
imports: import datetime
  import logging
  import tempfile
  import numpy
  from functools import partial
  from sklearn.preprocessing import MultiLabelBinarizer
  from small_text.classifiers.classification import EmbeddingMixin
  from small_text.integrations.pytorch.classifiers.base import PytorchClassifier
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
  from small_text.integrations.pytorch.models.kimcnn import KimCNN
  from small_text.utils.classification import get_splits
  from small_text.utils.context import build_pbar_context
  from small_text.utils.data import check_training_data, list_length
  from small_text.utils.annotations import early_stopping_deprecation_warning
  from small_text.utils.labels import csr_to_list, get_num_labels
  from small_text.utils.datetime import format_timedelta
  from small_text.utils.logging import verbosity_logger, VERBOSITY_MORE_VERBOSE
  from small_text.utils.system import get_tmp_dir_base
label_desc: Use image node_id 3 for calling the KimCNNEmbeddingMixin obj's underlying member method code with example usage: obj.create_embedding(best_label, sm, module_selector, tensors, text) and returns: batch_len