code: def build_vocab(opt, specials):
      """Build vocabs dict to be stored in the checkpoint
          based on vocab files having each line [token, count]
      Args:
          opt: src_vocab, tgt_vocab, n_src_feats
      Return:
          vocabs: {'src': pyonmttok.Vocab, 'tgt': pyonmttok.Vocab,
                   'src_feats' : [pyonmttok.Vocab, ...]},
                   'data_task': seq2seq or lm
                   'decoder_start_token': DefaultTokens.BOS
                  }
      """
  
      def _pad_vocab_to_multiple(vocab, multiple):
          vocab_size = len(vocab)
          if vocab_size % multiple == 0:
              return vocab
          target_size = int(ceil(vocab_size / multiple)) * multiple
          for i in range(target_size - vocab_size):
              vocab.add_token(DefaultTokens.VOCAB_PAD + str(i))
          return vocab
  
      default_specials = opt.default_specials
      vocabs = {}
      src_vocab = _read_vocab_file(
          opt.src_vocab, opt.src_words_min_frequency
      )
  
      src_specials = [
          item
          for item in (default_specials + specials["src"])
          if item not in src_vocab
      ]
  
      if DefaultTokens.SEP in src_specials and (
          "<0x0A>" in src_vocab or "Ċ" in src_vocab
      ):
          # this is hack: if the special separator ｟newline｠is returned because of the
          # "docify" transform.get_specials we don't add it if the corresponding newline code
          # is already included in the sentencepiece or BPE-with-gpt2-pretok.
          src_specials.remove(DefaultTokens.SEP)
  
      src_vocab = pyonmttok.build_vocab_from_tokens(
          src_vocab,
          maximum_size=opt.src_vocab_size,
          special_tokens=src_specials,
      )
      src_vocab.default_id = src_vocab[DefaultTokens.UNK]
  
      if opt.vocab_size_multiple > 1:
          src_vocab = _pad_vocab_to_multiple(
              src_vocab, opt.vocab_size_multiple
          )
      vocabs["src"] = src_vocab
      if opt.share_vocab:
          vocabs["tgt"] = src_vocab
      else:
          tgt_vocab = _read_vocab_file(
              opt.tgt_vocab, opt.tgt_words_min_frequency
          )
          tgt_specials = [
              item
              for item in (default_specials + specials["tgt"])
              if item not in tgt_vocab
          ]
          if DefaultTokens.SEP in tgt_specials and (
              "<0x0A>" in tgt_vocab or "Ċ" in src_vocab
          ):
              tgt_specials.remove(DefaultTokens.SEP)
          tgt_vocab = pyonmttok.build_vocab_from_tokens(
              tgt_vocab,
              maximum_size=opt.tgt_vocab_size,
              special_tokens=tgt_specials,
          )
          tgt_vocab.default_id = tgt_vocab[DefaultTokens.UNK]
          if opt.vocab_size_multiple > 1:
              tgt_vocab = _pad_vocab_to_multiple(
                  tgt_vocab, opt.vocab_size_multiple
              )
          vocabs["tgt"] = tgt_vocab
  
      if opt.n_src_feats > 0:
          src_feats_vocabs = []
          for i in range(opt.n_src_feats):
              src_f_vocab = _read_vocab_file(
                  f"{opt.src_vocab}_feat{i}", 1
              )
              src_f_vocab = pyonmttok.build_vocab_from_tokens(
                  src_f_vocab,
                  maximum_size=0,
                  minimum_frequency=1,
                  special_tokens=default_specials,
              )
              src_f_vocab.default_id = src_f_vocab[DefaultTokens.UNK]
              if opt.vocab_size_multiple > 1:
                  src_f_vocab = _pad_vocab_to_multiple(
                      src_f_vocab, opt.vocab_size_multiple
                  )
              src_feats_vocabs.append(src_f_vocab)
          vocabs["src_feats"] = src_feats_vocabs
  
      vocabs["data_task"] = opt.data_task
      vocabs["decoder_start_token"] = opt.decoder_start_token
  
      return vocabs
  
file_path: OpenNMT-py/onmt/inputters/inputter.py
imports: import os
  from math import ceil
  import codecs
  import pyonmttok
  from onmt.constants import DefaultTokens
label_desc: Use image node_id 1 for calling a global function with example usage: build_vocab(opt, specials) and returns: vocabs, vocab, vocab