code: def PruneEmptyStates(self):
      # Removes history-states that have no counts.
  
      # It's possible in principle for history-states to have no counts and
      # yet they cannot be pruned away because a higher-order version of the
      # state exists with nonzero counts, so we have to keep track of this.
      protected_histories = set()
  
      states_removed_per_hist_len = [0] * args.ngram_order
  
      for n in reversed(
          list(range(args.no_backoff_ngram_order, args.ngram_order))
      ):
          num_states_removed = 0
          for hist, counts_for_hist in self.counts[n].items():
              l = len(counts_for_hist.word_to_count)
              assert (
                  l > 0
                  and self.backoff_symbol
                  in counts_for_hist.word_to_count
              )
              if (
                  l == 1 and not hist in protected_histories
              ):  # only the backoff symbol has a count.
                  del self.counts[n][hist]
                  num_states_removed += 1
              else:
                  # if this state was not pruned away, then the state that
                  # it backs off to may not be pruned away either.
                  backoff_hist = hist[1:]
                  protected_histories.add(backoff_hist)
          states_removed_per_hist_len[n] = num_states_removed
      if args.verbose >= 1:
          print(
              "make_phone_lm.py: in PruneEmptyStates(), num states removed for "
              "each history-length was: "
              + str(states_removed_per_hist_len),
              file=sys.stderr,
          )
  
imports: import argparse
  import math
  import sys
  from collections import defaultdict
label_desc: Use image node_id 9 for calling the NgramCounts obj's underlying member method code with example usage: obj.PruneEmptyStates() without return types