class_docstr: Selects instances by expected gradient length [Set07]_.
class_docstr_tok: ["Selects","instances","by","expected","gradient","length","[","Set07","]","_","."]
code: def query(
      self,
      clf,
      dataset,
      indices_unlabeled,
      indices_labeled,
      y,
      n=10,
      pbar=None,
  ):
      self._validate_query_input(indices_unlabeled, n)
  
      if len(indices_unlabeled) == n:
          return np.array(indices_unlabeled)
  
      criterion = torch.nn.CrossEntropyLoss(reduction="none").to(
          self.device
      )
  
      collate_fn = clf._create_collate_fn()
      dataset_iter = dataloader(
          dataset,
          batch_size=self.batch_size,
          collate_fn=collate_fn,
          train=False,
      )
  
      clf.model.eval()
      clf.model.to(self.device)
  
      gradient_lengths = self.initialize_gradient_lengths_array(
          list_length(dataset)
      )
      pbar_context = build_pbar_context(
          "tqdm", tqdm_kwargs={"total": list_length(dataset)}
      )
  
      offset = 0
      with pbar_context as pbar:
          for i, (dataset, *_) in enumerate(dataset_iter):
              self.compute_gradient_lengths(
                  clf, criterion, gradient_lengths, offset, dataset
              )
  
              batch_len = dataset.size(0)
              offset += batch_len
  
              if pbar is not None:
                  pbar.update(batch_len)
  
      return self.finalize_results(
          n, indices_unlabeled, gradient_lengths
      )
  
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 2 for calling the ExpectedGradientLength obj's underlying member method code with example usage: obj.query(clf, dataset, indices_unlabeled, indices_labeled, y, n, pbar) and returns: self, np