class_docstr: Class for representing ImageNet/WordNet hierarchy. 
class_docstr_tok: ["Class","for","representing","ImageNet\/WordNet","hierarchy","."]
docstr: Get superclasses by grouping together classes from the ImageNet dataset.
  
  Args:
      n_superclasses (int) : Number of superclasses desired
      ancestor_wnid (str) : (optional) WordNet ID that can be used to specify
                          common ancestor for the selected superclasses
      superclass_lowest (set of str) : (optional) Set of WordNet IDs of nodes
                          that shouldn't be further sub-classes
      balanced (bool) : If True, all the superclasses will have the same number
                      of ImageNet subclasses
  
  Returns:
      superclass_wnid (list): List of WordNet IDs of superclasses
      class_ranges (list of sets): List of ImageNet subclasses per superclass
      label_map (dict): Mapping from class number to human-interpretable description
                      for each superclass
docstr_tok: ["Get","superclasses","by","grouping","together","classes","from","the","ImageNet","dataset",".","Args",":","n_superclasses","(","int",")",":","Number","of","superclasses","desired","ancestor_wnid","(","str",")",":","(","optional",")","WordNet","ID","that","can","be","used","to","specify","common","ancestor","for","the","selected","superclasses","superclass_lowest","(","set","of","str",")",":","(","optional",")","Set","of","WordNet","IDs","of","nodes","that","should","n't","be","further","sub-classes","balanced","(","bool",")",":","If","True",",","all","the","superclasses","will","have","the","same","number","of","ImageNet","subclasses","Returns",":","superclass_wnid","(","list",")",":","List","of","WordNet","IDs","of","superclasses","class_ranges","(","list","of","sets",")",":","List","of","ImageNet","subclasses","per","superclass","label_map","(","dict",")",":","Mapping","from","class","number","to","human-interpretable","description","for","each","superclass"]
code: def get_superclasses(
      self,
      n_superclasses,
      ancestor_wnid=None,
      superclass_lowest=None,
      balanced=True,
  ):
      """
      Get superclasses by grouping together classes from the ImageNet dataset.
  
      Args:
          n_superclasses (int) : Number of superclasses desired
          ancestor_wnid (str) : (optional) WordNet ID that can be used to specify
                              common ancestor for the selected superclasses
          superclass_lowest (set of str) : (optional) Set of WordNet IDs of nodes
                              that shouldn't be further sub-classes
          balanced (bool) : If True, all the superclasses will have the same number
                          of ImageNet subclasses
  
      Returns:
          superclass_wnid (list): List of WordNet IDs of superclasses
          class_ranges (list of sets): List of ImageNet subclasses per superclass
          label_map (dict): Mapping from class number to human-interpretable description
                          for each superclass
      """
  
      assert superclass_lowest is None or not any(
          [
              self.is_ancestor(s1, s2)
              for s1, s2 in product(
                  superclass_lowest, superclass_lowest
              )
          ]
      )
  
      superclass_info = []
      for wnid, ndesc_in, ndesc_all in self.wnid_sorted:
          if len(superclass_info) == n_superclasses:
              break
  
          if ancestor_wnid is None or self.is_ancestor(
              ancestor_wnid, wnid
          ):
              keep_wnid = [True] * (len(superclass_info) + 1)
              superclass_info.append((wnid, ndesc_in))
  
              for ii, (w, d) in enumerate(superclass_info):
                  if self.is_ancestor(w, wnid):
                      if superclass_lowest and w in superclass_lowest:
                          keep_wnid[-1] = False
                      else:
                          keep_wnid[ii] = False
  
              for ii in range(len(superclass_info) - 1, -1, -1):
                  if not keep_wnid[ii]:
                      superclass_info.pop(ii)
  
      superclass_wnid = [w for w, _ in superclass_info]
      class_ranges, label_map = self.get_subclasses(
          superclass_wnid, balanced=balanced
      )
  
      return superclass_wnid, class_ranges, label_map
  
file_path: robustness/robustness/tools/imagenet_helpers.py
imports: import os
  import numpy
  import json
  from itertools import product
label_desc: Use image node_id 6 for calling the ImageNetHierarchy obj's underlying member method code with example usage: obj.get_superclasses(n_superclasses, ancestor_wnid, superclass_lowest, balanced) and returns: superclass_wnid,  class_ranges,  label_map