code: def build_fairseq_vocab(
      vocab_file: str,
      dictionary_class: Dictionary = Dictionary,
      special_token_replacements: Dict[str, Token] = None,
      max_vocab: int = -1,
      min_count: int = -1,
      tokens_to_add: Optional[List[str]] = None,
  ) -> Vocabulary:
      """
      Function builds a PyText vocabulary for models pre-trained using Fairseq
      modules. The dictionary class can take any Fairseq Dictionary class
      and is used to load the vocab file.
      """
      dictionary = dictionary_class.load(vocab_file)
      # finalize will sort the dict based on frequency so only do this if
      # a min_count or max_vocab size is specified
      if min_count > 0 or max_vocab > 0:
          dictionary.finalize(
              threshold=min_count, nwords=max_vocab, padding_factor=1
          )
      if tokens_to_add:
          for token in tokens_to_add:
              dictionary.add_symbol(token)
      return Vocabulary(
          dictionary.symbols,
          dictionary.count,
          replacements=special_token_replacements,
      )
  
imports: from typing import Any, Dict, List, Optional, Tuple
  import torch
  from fairseq.data.dictionary import Dictionary
  from fairseq.data.legacy.masked_lm_dictionary import BertDictionary
  from pytext import resources
  from pytext.common.constants import Token
  from pytext.config.component import ComponentType, create_component
  from pytext.data.tensorizers import Tensorizer, TensorizerScriptImpl
  from pytext.data.tokenizers import Tokenizer, WordPieceTokenizer
  from pytext.data.utils import BOS, EOS, MASK, PAD, UNK, Vocabulary
  from pytext.torchscript.tensorizer.tensorizer import VocabLookup
  from pytext.torchscript.utils import pad_2d_mask, ScriptBatchInput
  from pytext.torchscript.vocab import ScriptVocabulary
  from pytext.utils.file_io import PathManager
  from pytext.utils.lazy import lazy_property
  from pytorch.text.fb.utils.transform_utils import pad_2d
label_desc: Use image node_id 1 for calling a global function with example usage: build_fairseq_vocab(vocab_file, dictionary_class, special_token_replacements, max_vocab, min_count, tokens_to_add) and returns: Vocabulary