class_docstr: Represents a vocabulary that can be built from a dataset.
docstr: Builds a vocabulary over tokens with optional minimum frequency.
  
  Args:
    tokenized_sequences: Iterable of token sequences to build the vocabulary.
    min_freq: The minimum frequency of each token to be included. Default: 1.
docstr_tok: ["Builds","a","vocabulary","over","tokens","with","optional","minimum","frequency",".","Args",":","tokenized_sequences",":","Iterable","of","token","sequences","to","build","the","vocabulary",".","min_freq",":","The","minimum","frequency","of","each","token","to","be","included",".","Default",":","1","."]
code: def build(
      self,
      tokenized_sequences: Iterable[Sequence[bytes]],
      min_freq: int = 1,
  ):
      """Builds a vocabulary over tokens with optional minimum frequency.
  
      Args:
        tokenized_sequences: Iterable of token sequences to build the vocabulary.
        min_freq: The minimum frequency of each token to be included. Default: 1.
      """
      # Count all the tokens.
      counter = collections.Counter()
      for token_sequence in tokenized_sequences:
          counter.update(token_sequence)
  
      # Add special tokens to the start of vocab.
      vocab = collections.OrderedDict()
      for token in self.special_tokens:
          vocab[token] = len(vocab)
  
      # Add all other tokens to the vocab if their frequency is >= min_freq.
      for token, freq in sorted(
          # Sort by frequency (from high to low), and then by token string.
          # This makes sure high frequency tokens get a low token ID.
          counter.items(),
          key=lambda token_freq: (-token_freq[1], token_freq[0]),
      ):
          if freq >= min_freq:
              vocab[token] = len(vocab)
  
      logging.info("Number of unfiltered tokens: %d", len(counter))
      logging.info("Vocabulary size: %d", len(vocab))
      self.vocab = vocab
  
file_path: flax/examples/sst2/vocabulary.py
imports: import collections
  from typing import Iterable, Optional, Sequence
  from absl import logging
label_desc: Use image node_id 2 for calling the Vocabulary obj's underlying member method code with example usage: obj.build(tokenized_sequences, min_freq) without return types