class_docstr: Helper class for aggregating and building `Vocabulary` objects.
class_docstr_tok: ["Helper","class","for","aggregating","and","building","`","Vocabulary","`","objects","."]
code: def truncate_to_vocab_size(
      self, vocab_size=-1, min_counts=-1
  ) -> None:
      if len(self._counter) > vocab_size > 0:
          self._counter = Counter(
              dict(self._counter.most_common(vocab_size))
          )
  
      if len(self._counter) > 0 and min_counts > 0:
          self._counter = Counter(
              {
                  k: v
                  for k, v in self._counter.items()
                  if v >= min_counts
              }
          )
  
imports: import itertools
  from collections import Counter
  from typing import Dict, List, Optional, Tuple
  import torch
  from pytext.common.constants import SpecialTokens, Token
  from pytext.utils import cuda, precision
label_desc: Use image node_id 7 for calling the VocabBuilder obj's underlying member method code with example usage: obj.truncate_to_vocab_size(vocab_size, min_counts) without return types