code: def build_pruned_vocab(
      raw_vocab: Counter,
      num_words: Optional[int] = None,
      min_count: int = 1,
      pad_to_multiple_of: Optional[int] = None,
  ) -> Vocab:
      """
      Creates a vocabulary mapping from words to ids. Increasing integer ids are assigned by word frequency,
      using lexical sorting as a tie breaker. The only exception to this are special symbols such as the padding symbol
      (PAD).
  
      :param raw_vocab: Raw token counts.
      :param num_words: Optional maximum number of words in the vocabulary.
      :param min_count: Minimum occurrences of words to be included in the vocabulary.
      :param pad_to_multiple_of: If not None, pads the vocabulary to a size that is the next multiple of this int.
      :return: Word-to-id mapping.
      """
      # For words with the same count, they will be ordered reverse alphabetically.
      # Not an issue since we only care for consistency
      pruned_vocab = [
          w
          for _, w in sorted(
              (
                  (c, w)
                  for w, c in raw_vocab.items()
                  if c >= min_count and w not in C.VOCAB_SYMBOLS
              ),
              reverse=True,
          )
      ]
  
      if num_words is not None:
          vocab = list(islice(pruned_vocab, num_words))
          num_words_log = str(num_words)
      else:
          vocab = pruned_vocab
          num_words_log = "None"
  
      if pad_to_multiple_of is not None:
          current_vocab_size = len(vocab) + len(C.VOCAB_SYMBOLS)
          rest = current_vocab_size % pad_to_multiple_of
          padded_vocab_size = (
              current_vocab_size
              if rest == 0
              else current_vocab_size + pad_to_multiple_of - rest
          )
          logger.info(
              "Padding vocabulary to a multiple of %d: %d -> %d",
              pad_to_multiple_of,
              current_vocab_size,
              padded_vocab_size,
          )
          pad_entries = [
              C.PAD_FORMAT % idx
              for idx in range(current_vocab_size, padded_vocab_size)
          ]
          pad_to_multiple_log = str(pad_to_multiple_of)
      else:
          pad_entries = []
          pad_to_multiple_log = "None"
  
      word_to_id = {
          word: idx
          for idx, word in enumerate(
              chain(C.VOCAB_SYMBOLS, vocab, pad_entries)
          )
      }
      logger.info(
          "Vocabulary: types: %d/%d/%d/%d (initial/min_pruned/max_pruned/+special) "
          + "[min_frequency=%d, max_num_types=%s, pad_to_multiple_of=%s]",
          len(raw_vocab),
          len(pruned_vocab),
          len(vocab),
          len(word_to_id),
          min_count,
          num_words_log,
          pad_to_multiple_log,
      )
  
      # Important: pad symbol becomes index 0
      assert word_to_id[C.PAD_SYMBOL] == C.PAD_ID
      return word_to_id
  
imports: import argparse
  import json
  import logging
  import os
  from collections import Counter
  from itertools import chain, islice
  from typing import Dict, Iterable, List, Optional, Tuple, Callable
  from sockeye.log import setup_main_logger
  from .None import constants
  from .None import utils
label_desc: Use image node_id 4 for calling a global function with example usage: build_pruned_vocab(raw_vocab, num_words, min_count, pad_to_multiple_of) and returns: word_to_id