code: def main():
      parser = argparse.ArgumentParser(
          description="embeddings_to_torch.py"
      )
      parser.add_argument(
          "-emb_file_both",
          required=False,
          help="loads Embeddings for both source and target "
          "from this file.",
      )
      parser.add_argument(
          "-emb_file_enc",
          required=False,
          help="source Embeddings from this file",
      )
      parser.add_argument(
          "-emb_file_dec",
          required=False,
          help="target Embeddings from this file",
      )
      parser.add_argument(
          "-output_file",
          required=True,
          help="Output file for the prepared data",
      )
      parser.add_argument(
          "-dict_file", required=True, help="Dictionary file"
      )
      parser.add_argument(
          "-verbose", action="store_true", default=False
      )
      parser.add_argument(
          "-skip_lines",
          type=int,
          default=0,
          help="Skip first lines of the embedding file",
      )
      parser.add_argument(
          "-type", choices=["GloVe", "word2vec"], default="GloVe"
      )
      opt = parser.parse_args()
  
      enc_vocab, dec_vocab = get_vocabs(opt.dict_file)
  
      # Read in embeddings
      skip_lines = 1 if opt.type == "word2vec" else opt.skip_lines
      if opt.emb_file_both is not None:
          if opt.emb_file_enc is not None:
              raise ValueError(
                  "If --emb_file_both is passed in, you should not"
                  "set --emb_file_enc."
              )
          if opt.emb_file_dec is not None:
              raise ValueError(
                  "If --emb_file_both is passed in, you should not"
                  "set --emb_file_dec."
              )
          set_of_src_and_tgt_vocab = set(enc_vocab.ids_to_tokens) | set(
              dec_vocab.ids_to_tokens
          )
          logger.info(
              "Reading encoder and decoder embeddings from {}".format(
                  opt.emb_file_both
              )
          )
          src_vectors, total_vec_count = read_embeddings(
              opt.emb_file_both, skip_lines, set_of_src_and_tgt_vocab
          )
          tgt_vectors = src_vectors
          logger.info(
              "\tFound {} total vectors in file".format(total_vec_count)
          )
      else:
          if opt.emb_file_enc is None:
              raise ValueError(
                  "If --emb_file_enc not provided. Please specify "
                  "the file with encoder embeddings, or pass in "
                  "--emb_file_both"
              )
          if opt.emb_file_dec is None:
              raise ValueError(
                  "If --emb_file_dec not provided. Please specify "
                  "the file with encoder embeddings, or pass in "
                  "--emb_file_both"
              )
          logger.info(
              "Reading encoder embeddings from {}".format(
                  opt.emb_file_enc
              )
          )
          src_vectors, total_vec_count = read_embeddings(
              opt.emb_file_enc,
              skip_lines,
              filter_set=set(enc_vocab.ids_to_tokens),
          )
          logger.info(
              "\tFound {} total vectors in file.".format(
                  total_vec_count
              )
          )
          logger.info(
              "Reading decoder embeddings from {}".format(
                  opt.emb_file_dec
              )
          )
          tgt_vectors, total_vec_count = read_embeddings(
              opt.emb_file_dec,
              skip_lines,
              filter_set=set(dec_vocab.ids_to_tokens),
          )
          logger.info(
              "\tFound {} total vectors in file".format(total_vec_count)
          )
      logger.info("After filtering to vectors in vocab:")
      logger.info(
          "\t* enc: %d match, %d missing, (%.2f%%)"
          % calc_vocab_load_stats(enc_vocab, src_vectors)
      )
      logger.info(
          "\t* dec: %d match, %d missing, (%.2f%%)"
          % calc_vocab_load_stats(dec_vocab, tgt_vectors)
      )
  
      # Write to file
      enc_output_file = opt.output_file + ".enc.pt"
      dec_output_file = opt.output_file + ".dec.pt"
      logger.info(
          "\nSaving embedding as:\n\t* enc: %s\n\t* dec: %s"
          % (enc_output_file, dec_output_file)
      )
      torch.save(
          convert_to_torch_tensor(src_vectors, enc_vocab),
          enc_output_file,
      )
      torch.save(
          convert_to_torch_tensor(tgt_vectors, dec_vocab),
          dec_output_file,
      )
      logger.info("\nDone.")
  
file_path: OpenNMT-py/tools/embeddings_to_torch.py
imports: from __future__ import division
  import six
  import argparse
  import torch
  from onmt.utils.logging import init_logger, logger
  from onmt.inputters.inputter import dict_to_vocabs
label_desc: Use image node_id 5 for calling a global function with example usage: main() without return types