class_docstr: Selects instances using the EGL-word strategy [ZLW17]_.
  
  The EGL-word strategy works as follows:
  
  1. For every instance and class the gradient norm is computed per word.
     The score for each (instance, class) pair is the norm of the word with the
     highest gradient norm value.
  2. These scores are then summed up over all classes.
     The result is one score per instance.
  
  Finally, the instances are selected by maximum score.
  
  Notes
  -----
  - An embedding layer is required for this strategy.
  - This strategy was designed for the `KimCNN` model and might not work for other models
    even if they posses an embedding layer.
class_docstr_tok: ["Selects","instances","using","the","EGL-word","strategy","[","ZLW17","]","_",".","The","EGL-word","strategy","works","as","follows",":","1",".","For","every","instance","and","class","the","gradient","norm","is","computed","per","word",".","The","score","for","each","(","instance",",","class",")","pair","is","the","norm","of","the","word","with","the","highest","gradient","norm","value",".","2",".","These","scores","are","then","summed","up","over","all","classes",".","The","result","is","one","score","per","instance",".","Finally",",","the","instances","are","selected","by","maximum","score",".","Notes","--","--","-","-","An","embedding","layer","is","required","for","this","strategy",".","-","This","strategy","was","designed","for","the","`","KimCNN","`","model","and","might","not","work","for","other","models","even","if","they","posses","an","embedding","layer","."]
code: def compute_gradient_lengths(
      self, clf, criterion, gradient_lengths, offset, x
  ):
      self._words = torch.unique(x, dim=1).to(self.device)
  
      batch_len = x.size(0)
      all_classes = torch.cuda.LongTensor(
          [batch_len * [i] for i in range(self.num_classes)]
      )
      gradients = self.initialize_gradients(batch_len)
  
      x = x.to(self.device, non_blocking=True)
      clf.model.zero_grad()
  
      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)
  
              # Contrary to ExpectedGradientLength, compute_gradients operates on text
              self.compute_gradient_length(clf, x, sm, gradients, j, k)
  
      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 3 for calling the ExpectedGradientLengthMaxWord obj's underlying member method code with example usage: obj.compute_gradient_lengths(clf, criterion, gradient_lengths, offset, x) without return types