class_docstr: Selects instances by expected gradient length [Set07]_.
class_docstr_tok: ["Selects","instances","by","expected","gradient","length","[","Set07","]","_","."]
code: def compute_gradient_lengths_batch(
      self, clf, criterion, x, gradients, all_classes
  ):
      batch_len = x.size(0)
  
      output = clf.model(x)
      with torch.no_grad():
          sm = F.softmax(output, dim=1)
  
      for j in range(self.num_classes):
          loss = criterion(output, all_classes[j])
  
          for k in range(batch_len):
              clf.model.zero_grad()
              loss[k].backward(retain_graph=True)
  
              self.compute_gradient_length(clf, sm, gradients, j, k)
  
imports: import numpy
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
  from small_text.query_strategies import constraints, QueryStrategy, EmbeddingBasedQueryStrategy
  from small_text.utils.clustering import init_kmeans_plusplus_safe
  from small_text.utils.context import build_pbar_context
  from small_text.utils.data import list_length
label_desc: Use image node_id 7 for calling the ExpectedGradientLength obj's underlying member method code with example usage: obj.compute_gradient_lengths_batch(clf, criterion, x, gradients, all_classes) without return types