class_docstr: Selects instances by expected gradient length [Set07]_.
class_docstr_tok: ["Selects","instances","by","expected","gradient","length","[","Set07","]","_","."]
code: def compute_gradient_lengths(
      self, clf, criterion, gradient_lengths, offset, x
  ):
      batch_len = x.size(0)
      all_classes = torch.LongTensor(
          [batch_len * [i] for i in range(self.num_classes)]
      )
      if self.device is not None and self.device != "cpu":
          all_classes = all_classes.to(self.device)
  
      gradients = self.initialize_gradients(batch_len)
  
      x = x.to(self.device, non_blocking=True)
      clf.model.zero_grad()
  
      self.compute_gradient_lengths_batch(
          clf, criterion, x, gradients, all_classes
      )
      self.aggregate_gradient_lengths_batch(
          batch_len, gradient_lengths, gradients, offset
      )
  
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 5 for calling the ExpectedGradientLength obj's underlying member method code with example usage: obj.compute_gradient_lengths(clf, criterion, gradient_lengths, offset, x) without return types